home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / GAS_1_38.ARJ / M68K.C < prev    next >
C/C++ Source or Header  |  1990-12-04  |  80KB  |  3,541 lines

  1. /* m68k.c  All the m68020 specific stuff in one convenient, huge,
  2.    slow to compile, easy to find file.
  3.    Copyright (C) 1987 Free Software Foundation, Inc.
  4.  
  5. This file is part of GAS, the GNU Assembler.
  6.  
  7. GAS is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. GAS is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GAS; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include <ctype.h>
  22.  
  23. #include "m68k-opcode.h"
  24. #include "as.h"
  25. #include "obstack.h"
  26. #include "frags.h"
  27. #include "struc-symbol.h"
  28. #include "flonum.h"
  29. #include "expr.h"
  30. #include "hash.h"
  31. #include "md.h"
  32. #include "m68k.h"
  33.  
  34. #ifdef M_SUN
  35. /* This variable contains the value to write out at the beginning of
  36.    the a.out file.  The 2<<16 means that this is a 68020 file instead
  37.    of an old-style 68000 file */
  38.  
  39. long omagic = 2<<16|OMAGIC;    /* Magic byte for header file */
  40. #else
  41. long omagic = OMAGIC;
  42. #endif
  43.  
  44.  
  45. /* This array holds the chars that always start a comment.  If the
  46.    pre-processor is disabled, these aren't very useful */
  47. const char comment_chars[] = "|";
  48.  
  49. /* This array holds the chars that only start a comment at the beginning of
  50.    a line.  If the line seems to have the form '# 123 filename'
  51.    .line and .file directives will appear in the pre-processed output */
  52. /* Note that input_file.c hand checks for '#' at the beginning of the
  53.    first line of the input file.  This is because the compiler outputs
  54.    #NO_APP at the beginning of its output. */
  55. /* Also note that '/*' will always start a comment */
  56. const char line_comment_chars[] = "#";
  57.  
  58. /* Chars that can be used to separate mant from exp in floating point nums */
  59. const char EXP_CHARS[] = "eE";
  60.  
  61. /* Chars that mean this number is a floating point constant */
  62. /* As in 0f12.456 */
  63. /* or    0d1.2345e12 */
  64.  
  65. const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
  66.  
  67. /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
  68.    changed in read.c .  Ideally it shouldn't have to know about it at all,
  69.    but nothing is ideal around here.
  70.  */
  71.  
  72. void fix_new();
  73. void install_operand();
  74. void install_gen_operand();
  75.  
  76. /* Its an arbitrary name:  This means I don't approve of it */
  77. /* See flames below */
  78. struct obstack robyn;
  79.  
  80. #define TAB(x,y)    (((x)<<2)+(y))
  81. #define TABTYPE(xy)     ((xy) >> 2)
  82. #define BYTE        0
  83. #define SHORT        1
  84. #define LONG        2
  85. #define SZ_UNDEF    3
  86.  
  87. #define BRANCH        1
  88. #define FBRANCH        2
  89. #define PCREL        3
  90. #define BCC68000        4
  91. #define DBCC            5
  92. #define PCLEA        6
  93.  
  94. /* BCC68000 is for patching in an extra jmp instruction for long offsets
  95.    on the 68000.  The 68000 doesn't support long branches with branchs */
  96.  
  97. /* This table desribes how you change sizes for the various types of variable
  98.    size expressions.  This version only supports two kinds. */
  99.  
  100. /* Note that calls to frag_var need to specify the maximum expansion needed */
  101. /* This is currently 10 bytes for DBCC */
  102.  
  103. /* The fields are:
  104.     How far Forward this mode will reach:
  105.     How far Backward this mode will reach:
  106.     How many bytes this mode will add to the size of the frag
  107.     Which mode to go to if the offset won't fit in this one
  108.  */
  109. const relax_typeS
  110. md_relax_table[] = {
  111. { 1,        1,        0,    0 },    /* First entries aren't used */
  112. { 1,        1,        0,    0 },    /* For no good reason except */
  113. { 1,        1,        0,    0 },    /* that the VAX doesn't either */
  114. { 1,        1,        0,    0 },
  115.  
  116. { (127),    (-128),        0,    TAB(BRANCH,SHORT)},
  117. { (32767),    (-32768),    2,    TAB(BRANCH,LONG) },
  118. { 0,        0,        4,    0 },
  119. { 1,        1,        0,    0 },
  120.  
  121. { 1,        1,        0,    0 },    /* FBRANCH doesn't come BYTE */
  122. { (32767),    (-32768),    2,    TAB(FBRANCH,LONG)},
  123. { 0,        0,        4,    0 },
  124. { 1,        1,        0,    0 },
  125.  
  126. { 1,        1,        0,    0 },    /* PCREL doesn't come BYTE */
  127. { (32767),    (-32768),    2,    TAB(PCREL,LONG)},
  128. { 0,        0,        4,    0 },
  129. { 1,        1,        0,    0 },
  130.  
  131. { (127),    (-128),        0,    TAB(BCC68000,SHORT)},
  132. { (32767),    (-32768),    2,    TAB(BCC68000,LONG) },
  133. { 0,        0,        6,    0 },    /* jmp long space */
  134. { 1,        1,        0,    0 },
  135.  
  136. { 1,        1,        0,    0 },    /* DBCC doesn't come BYTE */
  137. { (32767),    (-32768),    2,    TAB(DBCC,LONG) },
  138. { 0,        0,        10,    0 },    /* bra/jmp long space */
  139. { 1,        1,        0,    0 },
  140.  
  141. { 1,        1,        0,    0 },    /* PCLEA doesn't come BYTE */
  142. { 32767,    -32768,        2,    TAB(PCLEA,LONG) },
  143. { 0,        0,        6,    0 },
  144. { 1,        1,        0,    0 },
  145.  
  146. };
  147.  
  148. void    s_data1(),    s_data2(),    s_even(),    s_space();
  149. void    s_proc(),    float_cons();
  150.  
  151. /* These are the machine dependent pseudo-ops.  These are included so
  152.    the assembler can work on the output from the SUN C compiler, which
  153.    generates these.
  154.  */
  155.  
  156. /* This table describes all the machine specific pseudo-ops the assembler
  157.    has to support.  The fields are:
  158.        pseudo-op name without dot
  159.       function to call to execute this pseudo-op
  160.       Integer arg to pass to the function
  161.  */
  162. const pseudo_typeS md_pseudo_table[] = {
  163.     { "data1",    s_data1,    0    },
  164.     { "data2",    s_data2,    0    },
  165.     { "even",    s_even,        0    },
  166.     { "skip",    s_space,    0    },
  167.     { "proc",    s_proc,        0    },
  168.     { 0,        0,        0    }
  169. };
  170.  
  171.  
  172. /* #define isbyte(x)    ((x)>=-128 && (x)<=127) */
  173. /* #define isword(x)    ((x)>=-32768 && (x)<=32767) */
  174.  
  175. #define issbyte(x)    ((x)>=-128 && (x)<=127)
  176. #define isubyte(x)    ((x)>=0 && (x)<=255)
  177. #define issword(x)    ((x)>=-32768 && (x)<=32767)
  178. #define isuword(x)    ((x)>=0 && (x)<=65535)
  179.  
  180. #define isbyte(x)    ((x)>=-128 && (x)<=255)
  181. #define isword(x)    ((x)>=-32768 && (x)<=65535)
  182. #define islong(x)    (1)
  183.  
  184. extern char *input_line_pointer;
  185.  
  186. /* Operands we can parse:  (And associated modes)
  187.  
  188. numb:    8 bit num
  189. numw:    16 bit num
  190. numl:    32 bit num
  191. dreg:    data reg 0-7
  192. reg:    address or data register
  193. areg:    address register
  194. apc:    address register, PC, ZPC or empty string
  195. num:    16 or 32 bit num
  196. num2:    like num
  197. sz:    w or l        if omitted, l assumed
  198. scale:    1 2 4 or 8    if omitted, 1 assumed
  199.  
  200. 7.4 IMMED #num                --> NUM
  201. 0.? DREG  dreg                --> dreg
  202. 1.? AREG  areg                --> areg
  203. 2.? AINDR areg@                --> *(areg)
  204. 3.? AINC  areg@+            --> *(areg++)
  205. 4.? ADEC  areg@-            --> *(--areg)
  206. 5.? AOFF  apc@(numw)            --> *(apc+numw)    -- empty string and ZPC not allowed here
  207. 6.? AINDX apc@(num,reg:sz:scale)    --> *(apc+num+reg*scale)
  208. 6.? AINDX apc@(reg:sz:scale)        --> same, with num=0
  209. 6.? APODX apc@(num)@(num2,reg:sz:scale)    --> *(*(apc+num)+num2+reg*scale)
  210. 6.? APODX apc@(num)@(reg:sz:scale)    --> same, with num2=0
  211. 6.? AMIND apc@(num)@(num2)        --> *(*(apc+num)+num2) (previous mode without an index reg)
  212. 6.? APRDX apc@(num,reg:sz:scale)@(num2)    --> *(*(apc+num+reg*scale)+num2)
  213. 6.? APRDX apc@(reg:sz:scale)@(num2)    --> same, with num=0
  214. 7.0 ABSL  num:sz            --> *(num)
  215.           num                --> *(num) (sz L assumed)
  216. *** MSCR  otherreg            --> Magic
  217. With -l option
  218. 5.? AOFF  apc@(num)            --> *(apc+num) -- empty string and ZPC not allowed here still
  219.  
  220. examples:
  221.     #foo    #0x35    #12
  222.     d2
  223.     a4
  224.     a3@
  225.     a5@+
  226.     a6@-
  227.     a2@(12)    pc@(14)
  228.     a1@(5,d2:w:1)    @(45,d6:l:4)
  229.     pc@(a2)        @(d4)
  230.     etc . . .
  231.  
  232.  
  233. #name@(numw)    -->turn into PC rel mode
  234. apc@(num8,reg:sz:scale)        --> *(apc+num8+reg*scale)
  235.  
  236. */
  237.  
  238. #define IMMED    1
  239. #define DREG    2
  240. #define AREG    3
  241. #define AINDR    4
  242. #define ADEC    5
  243. #define AINC    6
  244. #define AOFF    7
  245. #define AINDX    8
  246. #define APODX    9
  247. #define AMIND    10
  248. #define APRDX    11
  249. #define ABSL    12
  250. #define MSCR    13
  251. #define REGLST    14
  252.  
  253. #define FAIL    0
  254. #define OK    1
  255.  
  256. /* DATA and ADDR have to be contiguous, so that reg-DATA gives 0-7==data reg,
  257.    8-15==addr reg for operands that take both types */
  258. #define DATA    1        /*   1- 8 == data registers 0-7 */
  259. #define ADDR    (DATA+8)    /*   9-16 == address regs 0-7 */
  260. #define FPREG    (ADDR+8)    /*  17-24 Eight FP registers */
  261. #define COPNUM    (FPREG+8)    /*  25-32 Co-processor #1-#8 */
  262.  
  263. #define PC    (COPNUM+8)    /*  33 Program counter */
  264. #define ZPC    (PC+1)        /*  34 Hack for Program space, but 0 addressing */
  265. #define SR    (ZPC+1)        /*  35 Status Reg */
  266. #define CCR    (SR+1)        /*  36 Condition code Reg */
  267.  
  268. /* These have to be in order for the movec instruction to work. */
  269. #define USP    (CCR+1)        /*  37 User Stack Pointer */
  270. #define ISP    (USP+1)        /*  38 Interrupt stack pointer */
  271. #define SFC    (ISP+1)        /*  39 */
  272. #define DFC    (SFC+1)        /*  40 */
  273. #define CACR    (DFC+1)        /*  41 */
  274. #define VBR    (CACR+1)    /*  42 */
  275. #define CAAR    (VBR+1)        /*  43 */
  276. #define MSP    (CAAR+1)    /*  44 */
  277.  
  278. #define FPI    (MSP+1)        /* 45 */
  279. #define FPS    (FPI+1)        /* 46 */
  280. #define FPC    (FPS+1)        /* 47 */
  281. /*
  282.  * these defines should be in m68k.c but
  283.  * i put them here to keep all the m68851 stuff
  284.  * together -rab
  285.  * JF--Make sure these #s don't clash with the ones in m68k.c
  286.  * That would be BAD.
  287.  */
  288. #define TC    (FPC+1)        /* 48 */
  289. #define DRP    (TC+1)        /* 49 */
  290. #define SRP    (DRP+1)        /* 50 */
  291. #define CRP    (SRP+1)        /* 51 */
  292. #define CAL    (CRP+1)        /* 52 */
  293. #define VAL    (CAL+1)        /* 53 */
  294. #define SCC    (VAL+1)        /* 54 */
  295. #define AC    (SCC+1)        /* 55 */
  296. #define BAD    (AC+1)        /* 56,57,58,59, 60,61,62,63 */
  297. #define BAC    (BAD+8)        /* 64,65,66,67, 68,69,70,71 */
  298. #define PSR    (BAC+8)        /* 72 */
  299. #define PCSR    (PSR+1)        /* 73 */
  300.  
  301.  
  302. /* Note that COPNUM==processor #1 -- COPNUM+7==#8, which stores as 000 */
  303. /* I think. . .  */
  304.  
  305. #define    SP    ADDR+7
  306.  
  307. /* JF these tables here are for speed at the expense of size */
  308. /* You can replace them with the #if 0 versions if you really
  309.    need space and don't mind it running a bit slower */
  310.  
  311. static char mklower_table[256];
  312. #define mklower(c) (mklower_table[(unsigned char)(c)])
  313. static char notend_table[256];
  314. static char alt_notend_table[256];
  315. #define notend(s) ( !(notend_table[(unsigned char)(*s)] || (*s==':' &&\
  316.  alt_notend_table[(unsigned char)(s[1])])))
  317.  
  318. #if 0
  319. #define mklower(c)    (isupper(c) ? tolower(c) : c)
  320. #endif
  321.  
  322.  
  323. struct m68k_exp {
  324.     char    *e_beg;
  325.     char    *e_end;
  326.     expressionS e_exp;
  327.     short    e_siz;        /* 0== default 1==short/byte 2==word 3==long */
  328. };
  329.  
  330. /* Internal form of an operand.  */
  331. struct m68k_op {
  332.     char    *error;        /* Couldn't parse it */
  333.     int    mode;        /* What mode this instruction is in.  */
  334.     unsigned long int    reg;        /* Base register */
  335.     struct m68k_exp *con1;
  336.     int    ireg;        /* Index register */
  337.     int    isiz;        /* 0==unspec  1==byte(?)  2==short  3==long  */
  338.     int    imul;        /* Multipy ireg by this (1,2,4,or 8) */
  339.     struct    m68k_exp *con2;
  340. };
  341.  
  342. /* internal form of a 68020 instruction */
  343. struct m68_it {
  344.     char    *error;
  345.     char    *args;        /* list of opcode info */
  346.     int    numargs;
  347.  
  348.     int    numo;        /* Number of shorts in opcode */
  349.     short    opcode[11];
  350.  
  351.     struct m68k_op operands[6];
  352.  
  353.     int    nexp;        /* number of exprs in use */
  354.     struct m68k_exp exprs[4];
  355.  
  356.     int    nfrag;        /* Number of frags we have to produce */
  357.     struct {
  358.         int fragoff;    /* Where in the current opcode[] the frag ends */
  359.         symbolS *fadd;
  360.         long int foff;
  361.         int fragty;
  362.     } fragb[4];
  363.  
  364.     int    nrel;        /* Num of reloc strucs in use */
  365.     struct    {
  366.         int    n;
  367.         symbolS    *add,
  368.             *sub;
  369.         long int off;
  370.         char    wid;
  371.         char    pcrel;
  372.     } reloc[5];        /* Five is enough??? */
  373. };
  374.  
  375. struct m68_it the_ins;        /* the instruction being assembled */
  376.  
  377.  
  378. /* Macros for adding things to the m68_it struct */
  379.  
  380. #define addword(w)    the_ins.opcode[the_ins.numo++]=(w)
  381.  
  382. /* Like addword, but goes BEFORE general operands */
  383. #define insop(w)    {int z;\
  384.  for(z=the_ins.numo;z>opcode->m_codenum;--z)\
  385.    the_ins.opcode[z]=the_ins.opcode[z-1];\
  386.  for(z=0;z<the_ins.nrel;z++)\
  387.    the_ins.reloc[z].n+=2;\
  388.  the_ins.opcode[opcode->m_codenum]=w;\
  389.  the_ins.numo++;\
  390. }
  391.  
  392.  
  393. #define add_exp(beg,end) (\
  394.     the_ins.exprs[the_ins.nexp].e_beg=beg,\
  395.     the_ins.exprs[the_ins.nexp].e_end=end,\
  396.     &the_ins.exprs[the_ins.nexp++]\
  397. )
  398.  
  399.  
  400. /* The numo+1 kludge is so we can hit the low order byte of the prev word. Blecch*/
  401. #define add_fix(width,exp,pc_rel) {\
  402.     the_ins.reloc[the_ins.nrel].n= ((width)=='B') ? (the_ins.numo*2-1) : \
  403.         (((width)=='b') ? ((the_ins.numo-1)*2) : (the_ins.numo*2));\
  404.     the_ins.reloc[the_ins.nrel].add=adds((exp));\
  405.     the_ins.reloc[the_ins.nrel].sub=subs((exp));\
  406.     the_ins.reloc[the_ins.nrel].off=offs((exp));\
  407.     the_ins.reloc[the_ins.nrel].wid=width;\
  408.     the_ins.reloc[the_ins.nrel++].pcrel=pc_rel;\
  409. }
  410.  
  411. #define add_frag(add,off,type)  {\
  412.     the_ins.fragb[the_ins.nfrag].fragoff=the_ins.numo;\
  413.     the_ins.fragb[the_ins.nfrag].fadd=add;\
  414.     the_ins.fragb[the_ins.nfrag].foff=off;\
  415.     the_ins.fragb[the_ins.nfrag++].fragty=type;\
  416. }
  417.  
  418. #define isvar(exp)    ((exp) && (adds(exp) || subs(exp)))
  419.  
  420. #define seg(exp)    ((exp)->e_exp.X_seg)
  421. #define adds(exp)    ((exp)->e_exp.X_add_symbol)
  422. #define subs(exp)    ((exp)->e_exp.X_subtract_symbol)
  423. #define offs(exp)    ((exp)->e_exp.X_add_number)
  424.  
  425.  
  426. struct m68_incant {
  427.     char *m_operands;
  428.     unsigned long m_opcode;
  429.     short m_opnum;
  430.     short m_codenum;
  431.     struct m68_incant *m_next;
  432. };
  433.  
  434. #define getone(x)    ((((x)->m_opcode)>>16)&0xffff)
  435. #define gettwo(x)    (((x)->m_opcode)&0xffff)
  436.  
  437.  
  438. /* JF modified this to handle cases where the first part of a symbol name
  439.    looks like a register */
  440.  
  441. int
  442. m68k_reg_parse(ccp)
  443. register char **ccp;
  444. {
  445.     register char c1,
  446.         c2,
  447.         c3,
  448.         c4;
  449.     register int n = 0,
  450.         ret = FAIL;
  451.  
  452.     c1=mklower(ccp[0][0]);
  453. #ifdef REGISTER_PREFIX
  454.     if(c1!=REGISTER_PREFIX)
  455.         return FAIL;
  456.     c1=mklower(ccp[0][1]);
  457.     c2=mklower(ccp[0][2]);
  458.     c3=mklower(ccp[0][3]);
  459.     c4=mklower(ccp[0][4]);
  460. #else
  461.     c2=mklower(ccp[0][1]);
  462.     c3=mklower(ccp[0][2]);
  463.     c4=mklower(ccp[0][3]);
  464. #endif
  465.     switch(c1) {
  466.     case 'a':
  467.         if(c2>='0' && c2<='7') {
  468.             n=2;
  469.             ret=ADDR+c2-'0';
  470.         }
  471. #ifdef m68851
  472.         else if (c2 == 'c') {
  473.             n = 2;
  474.             ret = AC;
  475.         }
  476. #endif
  477.         break;
  478. #ifdef m68851
  479.     case 'b':
  480.         if (c2 == 'a') {
  481.             if (c3 == 'd') {
  482.                 if (c4 >= '0' && c4 <= '7') {
  483.                     n = 4;
  484.                     ret = BAD + c4 - '0';
  485.                 }
  486.             }
  487.             if (c3 == 'c') {
  488.                 if (c4 >= '0' && c4 <= '7') {
  489.                     n = 4;
  490.                     ret = BAC + c4 - '0';
  491.                 }
  492.             }
  493.         }
  494.         break;
  495. #endif
  496.     case 'c':
  497. #ifdef m68851
  498.         if (c2 == 'a' && c3 == 'l') {
  499.             n = 3;
  500.             ret = CAL;
  501.         } else
  502. #endif
  503.             /* This supports both CCR and CC as the ccr reg. */
  504.         if(c2=='c' && c3=='r') {
  505.             n=3;
  506.             ret = CCR;
  507.         } else if(c2=='c') {
  508.             n=2;
  509.             ret = CCR;
  510.         } else if(c2=='a' && (c3=='a' || c3=='c') && c4=='r') {
  511.             n=4;
  512.             ret = c3=='a' ? CAAR : CACR;
  513.         }
  514. #ifdef m68851
  515.         else if (c2 == 'r' && c3 == 'p') {
  516.             n = 3;
  517.             ret = (CRP);
  518.         }
  519. #endif
  520.         break;
  521.     case 'd':
  522.         if(c2>='0' && c2<='7') {
  523.             n=2;
  524.             ret = DATA+c2-'0';
  525.         } else if(c2=='f' && c3=='c') {
  526.             n=3;
  527.             ret = DFC;
  528.         }
  529. #ifdef m68851
  530.         else if (c2 == 'r' && c3 == 'p') {
  531.             n = 3;
  532.             ret = (DRP);
  533.         }
  534. #endif
  535.         break;
  536.     case 'f':
  537.         if(c2=='p') {
  538.             if(c3>='0' && c3<='7') {
  539.                 n=3;
  540.                 ret = FPREG+c3-'0';
  541.                 if(c4==':')
  542.                     ccp[0][3]=',';
  543.             } else if(c3=='i') {
  544.                 n=3;
  545.                 ret = FPI;
  546.             } else if(c3=='s') {
  547.                 n= (c4 == 'r' ? 4 : 3);
  548.                 ret = FPS;
  549.             } else if(c3=='c') {
  550.                 n= (c4 == 'r' ? 4 : 3);
  551.                 ret = FPC;
  552.             }
  553.         }
  554.         break;
  555.     case 'i':
  556.         if(c2=='s' && c3=='p') {
  557.             n=3;
  558.             ret = ISP;
  559.         }
  560.         break;
  561.     case 'm':
  562.         if(c2=='s' && c3=='p') {
  563.             n=3;
  564.             ret = MSP;
  565.         }
  566.         break;
  567.     case 'p':
  568.         if(c2=='c') {
  569. #ifdef m68851
  570.             if(c3 == 's' && c4=='r') {
  571.                 n=4;
  572.                 ret = (PCSR);
  573.             } else
  574. #endif
  575.             {
  576.                 n=2;
  577.                 ret = PC;
  578.             }
  579.         }
  580. #ifdef m68851
  581.         else if (c2 == 's' && c3 == 'r') {
  582.             n = 3;
  583.             ret = (PSR);
  584.         }
  585. #endif
  586.         break;
  587.     case 's':
  588. #ifdef m68851
  589.         if (c2 == 'c' && c3 == 'c') {
  590.             n = 3;
  591.             ret = (SCC);
  592.         } else if (c2 == 'r' && c3 == 'p') {
  593.             n = 3;
  594.             ret = (SRP);
  595.         } else
  596. #endif
  597.         if(c2=='r') {
  598.             n=2;
  599.             ret = SR;
  600.         } else if(c2=='p') {
  601.             n=2;
  602.             ret = ADDR+7;
  603.         } else if(c2=='f' && c3=='c') {
  604.             n=3;
  605.             ret = SFC;
  606.         }
  607.         break;
  608. #ifdef m68851
  609.     case 't':
  610.         if(c2 == 'c') {
  611.             n=2;
  612.             ret=TC;
  613.         }
  614.         break;
  615. #endif
  616.     case 'u':
  617.         if(c2=='s' && c3=='p') {
  618.             n=3;
  619.             ret = USP;
  620.         }
  621.         break;
  622.     case 'v':
  623. #ifdef m68851
  624.         if (c2 == 'a' && c3 == 'l') {
  625.             n = 3;
  626.             ret = (VAL);
  627.         } else
  628. #endif
  629.         if(c2=='b' && c3=='r') {
  630.             n=3;
  631.             ret = VBR;
  632.         }
  633.         break;
  634.     case 'z':
  635.         if(c2=='p' && c3=='c') {
  636.             n=3;
  637.             ret = ZPC;
  638.         }
  639.         break;
  640.     default:
  641.         break;
  642.     }
  643.     if(n) {
  644. #ifdef REGISTER_PREFIX
  645.         n++;
  646. #endif
  647.         if(isalnum(ccp[0][n]) || ccp[0][n]=='_')
  648.             ret=FAIL;
  649.         else
  650.             ccp[0]+=n;
  651.     } else
  652.         ret = FAIL;
  653.     return ret;
  654. }
  655.  
  656. #define SKIP_WHITE()    { str++; if(*str==' ') str++;}
  657.  
  658. int
  659. m68k_ip_op(str,opP)
  660. char *str;
  661. register struct m68k_op *opP;
  662. {
  663.     char    *strend;
  664.     long    i;
  665.     char    *parse_index();
  666.  
  667.     if(*str==' ')
  668.         str++;
  669.         /* Find the end of the string */
  670.     if(!*str) {
  671.         /* Out of gas */
  672.         opP->error="Missing operand";
  673.         return FAIL;
  674.     }
  675.     for(strend=str;*strend;strend++)
  676.         ;
  677.     --strend;
  678.  
  679.         /* Guess what:  A constant.  Shar and enjoy */
  680.     if(*str=='#') {
  681.         str++;
  682.         opP->con1=add_exp(str,strend);
  683.         opP->mode=IMMED;
  684.         return OK;
  685.     }
  686.     i=m68k_reg_parse(&str);
  687.     if((i==FAIL || *str!='\0') && *str!='@') {
  688.         char *stmp;
  689.         char *index();
  690.  
  691.         if(i!=FAIL && (*str=='/' || *str=='-')) {
  692.             opP->mode=REGLST;
  693.             return get_regs(i,str,opP);
  694.         }
  695.         if(stmp=index(str,'@')) {
  696.             opP->con1=add_exp(str,stmp-1);
  697.             if(stmp==strend) {
  698.                 opP->mode=AINDX;
  699.                 return OK;
  700.             }
  701.             stmp++;
  702.             if(*stmp++!='(' || *strend--!=')') {
  703.                 opP->error="Malformed operand";
  704.                 return FAIL;
  705.             }
  706.             i=try_index(&stmp,opP);
  707.             opP->con2=add_exp(stmp,strend);
  708.             if(i==FAIL) opP->mode=AMIND;
  709.             else opP->mode=APODX;
  710.             return OK;
  711.         }
  712.         opP->mode=ABSL;
  713.         opP->con1=add_exp(str,strend);
  714.         return OK;
  715.     }
  716.     opP->reg=i;
  717.     if(*str=='\0') {
  718.         if(i>=DATA+0 && i<=DATA+7)
  719.             opP->mode=DREG;
  720.         else if(i>=ADDR+0 && i<=ADDR+7)
  721.             opP->mode=AREG;
  722.         else
  723.             opP->mode=MSCR;
  724.         return OK;
  725.     }
  726.     if((i<ADDR+0 || i>ADDR+7) && i!=PC && i!=ZPC && i!=FAIL) {    /* Can't indirect off non address regs */
  727.         opP->error="Invalid indirect register";
  728.         return FAIL;
  729.     }
  730.     if(*str!='@')
  731.         abort();
  732.     str++;
  733.     switch(*str) {
  734.     case '\0':
  735.         opP->mode=AINDR;
  736.         return OK;
  737.     case '-':
  738.         opP->mode=ADEC;
  739.         return OK;
  740.     case '+':
  741.         opP->mode=AINC;
  742.         return OK;
  743.     case '(':
  744.         str++;
  745.         break;
  746.     default:
  747.         opP->error="Junk after indirect";
  748.         return FAIL;
  749.     }
  750.         /* Some kind of indexing involved.  Lets find out how bad it is */
  751.     i=try_index(&str,opP);
  752.         /* Didn't start with an index reg, maybe its offset or offset,reg */
  753.     if(i==FAIL) {
  754.         char *beg_str;
  755.  
  756.         beg_str=str;
  757.         for(i=1;i;) {
  758.             switch(*str++) {
  759.             case '\0':
  760.                 opP->error="Missing )";
  761.                 return FAIL;
  762.             case ',': i=0; break;
  763.             case '(': i++; break;
  764.             case ')': --i; break;
  765.             }
  766.         }
  767.         /* if(str[-3]==':') {
  768.             int siz;
  769.  
  770.             switch(str[-2]) {
  771.             case 'b':
  772.             case 'B':
  773.                 siz=1;
  774.                 break;
  775.             case 'w':
  776.             case 'W':
  777.                 siz=2;
  778.                 break;
  779.             case 'l':
  780.             case 'L':
  781.                 siz=3;
  782.                 break;
  783.             default:
  784.                 opP->error="Specified size isn't :w or :l";
  785.                 return FAIL;
  786.             }
  787.             opP->con1=add_exp(beg_str,str-4);
  788.             opP->con1->e_siz=siz;
  789.         } else */
  790.             opP->con1=add_exp(beg_str,str-2);
  791.             /* Should be offset,reg */
  792.         if(str[-1]==',') {
  793.             i=try_index(&str,opP);
  794.             if(i==FAIL) {
  795.                 opP->error="Malformed index reg";
  796.                 return FAIL;
  797.             }
  798.         }
  799.     }
  800.         /* We've now got offset)   offset,reg)   or    reg) */
  801.  
  802.     if(*str=='\0') {
  803.         /* Th-the-thats all folks */
  804.         if(opP->reg==FAIL) opP->mode=AINDX;    /* Other form of indirect */
  805.         else if(opP->ireg==FAIL) opP->mode=AOFF;
  806.         else opP->mode=AINDX;
  807.         return OK;
  808.     }
  809.         /* Next thing had better be another @ */
  810.     if(*str!='@' || str[1]!='(') {
  811.         opP->error="junk after indirect";
  812.         return FAIL;
  813.     }
  814.     str+=2;
  815.     if(opP->ireg!=FAIL) {
  816.         opP->mode=APRDX;
  817.         i=try_index(&str,opP);
  818.         if(i!=FAIL) {
  819.             opP->error="Two index registers!  not allowed!";
  820.             return FAIL;
  821.         }
  822.     } else
  823.         i=try_index(&str,opP);
  824.     if(i==FAIL) {
  825.         char *beg_str;
  826.  
  827.         beg_str=str;
  828.         for(i=1;i;) {
  829.             switch(*str++) {
  830.             case '\0':
  831.                 opP->error="Missing )";
  832.                 return FAIL;
  833.             case ',': i=0; break;
  834.             case '(': i++; break;
  835.             case ')': --i; break;
  836.             }
  837.         }
  838.         opP->con2=add_exp(beg_str,str-2);
  839.         if(str[-1]==',') {
  840.             if(opP->ireg!=FAIL) {
  841.                 opP->error="Can't have two index regs";
  842.                 return FAIL;
  843.             }
  844.             i=try_index(&str,opP);
  845.             if(i==FAIL) {
  846.                 opP->error="malformed index reg";
  847.                 return FAIL;
  848.             }
  849.             opP->mode=APODX;
  850.         } else if(opP->ireg!=FAIL)
  851.             opP->mode=APRDX;
  852.         else
  853.             opP->mode=AMIND;
  854.     } else
  855.         opP->mode=APODX;
  856.     if(*str!='\0') {
  857.         opP->error="Junk after indirect";
  858.         return FAIL;
  859.     }
  860.     return OK;
  861. }
  862.  
  863. int
  864. try_index(s,opP)
  865. char **s;
  866. struct m68k_op *opP;
  867. {
  868.     register int    i;
  869.     char    *ss;
  870. #define SKIP_W()    { ss++; if(*ss==' ') ss++;}
  871.  
  872.     ss= *s;
  873.     /* SKIP_W(); */
  874.     i=m68k_reg_parse(&ss);
  875.     if(!(i>=DATA+0 && i<=ADDR+7)) {    /* if i is not DATA or ADDR reg */
  876.         *s=ss;
  877.         return FAIL;
  878.     }
  879.     opP->ireg=i;
  880.     /* SKIP_W(); */
  881.     if(*ss==')') {
  882.         opP->isiz=0;
  883.         opP->imul=1;
  884.         SKIP_W();
  885.         *s=ss;
  886.         return OK;
  887.     }
  888.     if(*ss!=':') {
  889.         opP->error="Missing : in index register";
  890.         *s=ss;
  891.         return FAIL;
  892.     }
  893.     SKIP_W();
  894.     switch(*ss) {
  895.     case 'w':
  896.     case 'W':
  897.         opP->isiz=2;
  898.         break;
  899.     case 'l':
  900.     case 'L':
  901.         opP->isiz=3;
  902.         break;
  903.     default:
  904.         opP->error="Index register size spec not :w or :l";
  905.         *s=ss;
  906.         return FAIL;
  907.     }
  908.     SKIP_W();
  909.     if(*ss==':') {
  910.         SKIP_W();
  911.         switch(*ss) {
  912.         case '1':
  913.         case '2':
  914.         case '4':
  915.         case '8':
  916.             opP->imul= *ss-'0';
  917.             break;
  918.         default:
  919.             opP->error="index multiplier not 1, 2, 4 or 8";
  920.             *s=ss;
  921.             return FAIL;
  922.         }
  923.         SKIP_W();
  924.     } else opP->imul=1;
  925.     if(*ss!=')') {
  926.         opP->error="Missing )";
  927.         *s=ss;
  928.         return FAIL;
  929.     }
  930.     SKIP_W();
  931.     *s=ss;
  932.     return OK;
  933. }
  934.  
  935. #ifdef TEST1    /* TEST1 tests m68k_ip_op(), which parses operands */
  936. main()
  937. {
  938.     char buf[128];
  939.     struct m68k_op thark;
  940.  
  941.     for(;;) {
  942.         if(!gets(buf))
  943.             break;
  944.         bzero(&thark,sizeof(thark));
  945.         if(!m68k_ip_op(buf,&thark)) printf("FAIL:");
  946.         if(thark.error)
  947.             printf("op1 error %s in %s\n",thark.error,buf);
  948.         printf("mode %d, reg %d, ",thark.mode,thark.reg);
  949.         if(thark.b_const)
  950.             printf("Constant: '%.*s',",1+thark.e_const-thark.b_const,thark.b_const);
  951.         printf("ireg %d, isiz %d, imul %d ",thark.ireg,thark.isiz,thark.imul);
  952.         if(thark.b_iadd)
  953.             printf("Iadd: '%.*s'",1+thark.e_iadd-thark.b_iadd,thark.b_iadd);
  954.         printf("\n");
  955.     }
  956.     exit(0);
  957. }
  958.  
  959. #endif
  960.  
  961.  
  962. static struct hash_control*   op_hash = NULL;    /* handle of the OPCODE hash table
  963.                    NULL means any use before m68_ip_begin()
  964.                    will crash */
  965.  
  966.  
  967. /*
  968.  *        m 6 8 _ i p ( )
  969.  *
  970.  * This converts a string into a 68k instruction.
  971.  * The string must be a bare single instruction in sun format
  972.  * with RMS-style 68020 indirects
  973.  *  (example:  )
  974.  *
  975.  * It provides some error messages: at most one fatal error message (which
  976.  * stops the scan) and at most one warning message for each operand.
  977.  * The 68k instruction is returned in exploded form, since we have no
  978.  * knowledge of how you parse (or evaluate) your expressions.
  979.  * We do however strip off and decode addressing modes and operation
  980.  * mnemonic.
  981.  *
  982.  * This function's value is a string. If it is not "" then an internal
  983.  * logic error was found: read this code to assign meaning to the string.
  984.  * No argument string should generate such an error string:
  985.  * it means a bug in our code, not in the user's text.
  986.  *
  987.  * You MUST have called m86_ip_begin() once and m86_ip_end() never before using
  988.  * this function.
  989.  */
  990.  
  991. /* JF this function no longer returns a useful value.  Sorry */
  992. void
  993. m68_ip (instring)
  994. char    *instring;
  995. {
  996.     register char *p;
  997.     register struct m68k_op *opP;
  998.     register struct m68_incant *opcode;
  999.     register char *s;
  1000.     register int tmpreg,
  1001.         baseo,
  1002.         outro,
  1003.         nextword;
  1004.     int    siz1,
  1005.         siz2;
  1006.     char    c;
  1007.     int    losing;
  1008.     int    opsfound;
  1009.     char    *crack_operand();
  1010.     LITTLENUM_TYPE words[6];
  1011.     LITTLENUM_TYPE *wordp;
  1012.  
  1013.     if (*instring == ' ')
  1014.         instring++;            /* skip leading whitespace */
  1015.  
  1016.   /* Scan up to end of operation-code, which MUST end in end-of-string
  1017.      or exactly 1 space. */
  1018.     for (p = instring; *p != '\0'; p++)
  1019.         if (*p == ' ')
  1020.             break;
  1021.  
  1022.  
  1023.     if (p == instring) {
  1024.         the_ins.error = "No operator";
  1025.         the_ins.opcode[0] = NULL;
  1026.         /* the_ins.numo=1; */
  1027.         return;
  1028.     }
  1029.  
  1030.   /* p now points to the end of the opcode name, probably whitespace.
  1031.      make sure the name is null terminated by clobbering the whitespace,
  1032.      look it up in the hash table, then fix it back. */   
  1033.     c = *p;
  1034.     *p = '\0';
  1035.     opcode = (struct m68_incant *)hash_find (op_hash, instring);
  1036.     *p = c;
  1037.  
  1038.     if (opcode == NULL) {
  1039.         the_ins.error = "Unknown operator";
  1040.         the_ins.opcode[0] = NULL;
  1041.         /* the_ins.numo=1; */
  1042.         return;
  1043.     }
  1044.  
  1045.   /* found a legitimate opcode, start matching operands */
  1046.     for(opP= &the_ins.operands[0];*p;opP++) {
  1047.         p = crack_operand (p, opP);
  1048.         if(opP->error) {
  1049.             the_ins.error=opP->error;
  1050.             return;
  1051.         }
  1052.     }
  1053.  
  1054.     opsfound=opP- &the_ins.operands[0];
  1055.     /* This ugly hack is to support the floating pt opcodes in their standard form */
  1056.     /* Essentially, we fake a first enty of type COP#1 */
  1057.     if(opcode->m_operands[0]=='I') {
  1058.         int    n;
  1059.  
  1060.         for(n=opsfound;n>0;--n)
  1061.             the_ins.operands[n]=the_ins.operands[n-1];
  1062.  
  1063.         /* bcopy((char *)(&the_ins.operands[0]),(char *)(&the_ins.operands[1]),opsfound*sizeof(the_ins.operands[0])); */
  1064.         bzero((char *)(&the_ins.operands[0]),sizeof(the_ins.operands[0]));
  1065.         the_ins.operands[0].mode=MSCR;
  1066.         the_ins.operands[0].reg=COPNUM;        /* COP #1 */
  1067.         opsfound++;
  1068.     }
  1069.         /* We've got the operands.  Find an opcode that'll
  1070.            accept them */
  1071.     for(losing=0;;) {
  1072.         if(opsfound!=opcode->m_opnum)
  1073.             losing++;
  1074.         else for(s=opcode->m_operands,opP= &the_ins.operands[0];*s && !losing;s+=2,opP++) {
  1075.                 /* Warning: this switch is huge! */
  1076.                 /* I've tried to organize the cases into  this order:
  1077.                    non-alpha first, then alpha by letter.  lower-case goes directly
  1078.                    before uppercase counterpart. */
  1079.                 /* Code with multiple case ...: gets sorted by the lowest case ...
  1080.                    it belongs to.  I hope this makes sense. */
  1081.             switch(*s) {
  1082.             case '!':
  1083.                 if(opP->mode==MSCR || opP->mode==IMMED ||
  1084.  opP->mode==DREG || opP->mode==AREG || opP->mode==AINC || opP->mode==ADEC || opP->mode==REGLST)
  1085.                     losing++;
  1086.                 break;
  1087.  
  1088.             case '#':
  1089.                 if(opP->mode!=IMMED)
  1090.                     losing++;
  1091.                 else {
  1092.                     long t;
  1093.  
  1094.                     t=get_num(opP->con1,80);
  1095.                     if(s[1]=='b' && !isbyte(t))
  1096.                         losing++;
  1097.                     else if(s[1]=='w' && !isword(t))
  1098.                         losing++;
  1099.                 }
  1100.                 break;
  1101.  
  1102.             case '^':
  1103.             case 'T':
  1104.                 if(opP->mode!=IMMED)
  1105.                     losing++;
  1106.                 break;
  1107.  
  1108.             case '$':
  1109.                 if(opP->mode==MSCR || opP->mode==AREG ||
  1110.  opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC || opP->mode==REGLST)
  1111.                     losing++;
  1112.                 break;
  1113.  
  1114.             case '%':
  1115.                 if(opP->mode==MSCR || opP->reg==PC ||
  1116.  opP->reg==ZPC || opP->mode==REGLST)
  1117.                     losing++;
  1118.                 break;
  1119.  
  1120.  
  1121.             case '&':
  1122.                 if(opP->mode==MSCR || opP->mode==DREG ||
  1123.  opP->mode==AREG || opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC ||
  1124.  opP->mode==AINC || opP->mode==ADEC || opP->mode==REGLST)
  1125.                     losing++;
  1126.                 break;
  1127.  
  1128.             case '*':
  1129.                 if(opP->mode==MSCR || opP->mode==REGLST)
  1130.                     losing++;
  1131.                 break;
  1132.  
  1133.             case '+':
  1134.                 if(opP->mode!=AINC)
  1135.                     losing++;
  1136.                 break;
  1137.  
  1138.             case '-':
  1139.                 if(opP->mode!=ADEC)
  1140.                     losing++;
  1141.                 break;
  1142.  
  1143.             case '/':
  1144.                 if(opP->mode==MSCR || opP->mode==AREG ||
  1145.  opP->mode==AINC || opP->mode==ADEC || opP->mode==IMMED || opP->mode==REGLST)
  1146.                     losing++;
  1147.                 break;
  1148.  
  1149.             case ';':
  1150.                 if(opP->mode==MSCR || opP->mode==AREG || opP->mode==REGLST)
  1151.                     losing++;
  1152.                 break;
  1153.  
  1154.             case '?':
  1155.                 if(opP->mode==MSCR || opP->mode==AREG ||
  1156.  opP->mode==AINC || opP->mode==ADEC || opP->mode==IMMED || opP->reg==PC ||
  1157.  opP->reg==ZPC || opP->mode==REGLST)
  1158.                     losing++;
  1159.                 break;
  1160.  
  1161.             case '@':
  1162.                 if(opP->mode==MSCR || opP->mode==AREG ||
  1163.  opP->mode==IMMED || opP->mode==REGLST)
  1164.                     losing++;
  1165.                 break;
  1166.  
  1167.             case '~':        /* For now! (JF FOO is this right?) */
  1168.                 if(opP->mode==MSCR || opP->mode==DREG ||
  1169.  opP->mode==AREG || opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC || opP->mode==REGLST)
  1170.                     losing++;
  1171.                 break;
  1172.  
  1173.             case 'A':
  1174.                 if(opP->mode!=AREG)
  1175.                     losing++;
  1176.                 break;
  1177.  
  1178.             case 'B':    /* FOO */
  1179.                 if(opP->mode!=ABSL)
  1180.                     losing++;
  1181.                 break;
  1182.  
  1183.             case 'C':
  1184.                 if(opP->mode!=MSCR || opP->reg!=CCR)
  1185.                     losing++;
  1186.                 break;
  1187.  
  1188.             case 'd':    /* FOO This mode is a KLUDGE!! */
  1189.                 if(opP->mode!=AOFF && (opP->mode!=ABSL ||
  1190.  opP->con1->e_beg[0]!='(' || opP->con1->e_end[0]!=')'))
  1191.                     losing++;
  1192.                 break;
  1193.  
  1194.             case 'D':
  1195.                 if(opP->mode!=DREG)
  1196.                     losing++;
  1197.                 break;
  1198.  
  1199.             case 'F':
  1200.                 if(opP->mode!=MSCR || opP->reg<(FPREG+0) || opP->reg>(FPREG+7))
  1201.                     losing++;
  1202.                 break;
  1203.  
  1204.             case 'I':
  1205.                 if(opP->mode!=MSCR || opP->reg<COPNUM ||
  1206.  opP->reg>=COPNUM+7)
  1207.                     losing++;
  1208.                 break;
  1209.  
  1210.             case 'J':
  1211.                 if(opP->mode!=MSCR || opP->reg<USP || opP->reg>MSP)
  1212.                     losing++;
  1213.                 break;
  1214.  
  1215.             case 'k':
  1216.                 if(opP->mode!=IMMED)
  1217.                     losing++;
  1218.                 break;
  1219.  
  1220.             case 'l':
  1221.             case 'L':
  1222.                 if(opP->mode==DREG || opP->mode==AREG || opP->mode==FPREG) {
  1223.                     if(s[1]=='8')
  1224.                         losing++;
  1225.                     else {
  1226.                         opP->mode=REGLST;
  1227.                         opP->reg=1<<(opP->reg-DATA);
  1228.                     }
  1229.                 } else if(opP->mode!=REGLST) {
  1230.                     losing++;
  1231.                 } else if(s[1]=='8' && opP->reg&0x0FFffFF)
  1232.                     losing++;
  1233.                 else if(s[1]=='3' && opP->reg&0x7000000)
  1234.                     losing++;
  1235.                 break;
  1236.  
  1237.             case 'M':
  1238.                 if(opP->mode!=IMMED)
  1239.                     losing++;
  1240.                 else {
  1241.                     long t;
  1242.  
  1243.                     t=get_num(opP->con1,80);
  1244.                     if(!issbyte(t) || isvar(opP->con1))
  1245.                         losing++;
  1246.                 }
  1247.                 break;
  1248.  
  1249.             case 'O':
  1250.                 if(opP->mode!=DREG && opP->mode!=IMMED)
  1251.                     losing++;
  1252.                 break;
  1253.  
  1254.             case 'Q':
  1255.                 if(opP->mode!=IMMED)
  1256.                     losing++;
  1257.                 else {
  1258.                     long t;
  1259.  
  1260.                     t=get_num(opP->con1,80);
  1261.                     if(t<1 || t>8 || isvar(opP->con1))
  1262.                         losing++;
  1263.                 }
  1264.                 break;
  1265.  
  1266.             case 'R':
  1267.                 if(opP->mode!=DREG && opP->mode!=AREG)
  1268.                     losing++;
  1269.                 break;
  1270.  
  1271.             case 's':
  1272.                 if(opP->mode!=MSCR || !(opP->reg==FPI || opP->reg==FPS || opP->reg==FPC))
  1273.                     losing++;
  1274.                 break;
  1275.  
  1276.             case 'S':
  1277.                 if(opP->mode!=MSCR || opP->reg!=SR)
  1278.                     losing++;
  1279.                 break;
  1280.  
  1281.             case 'U':
  1282.                 if(opP->mode!=MSCR || opP->reg!=USP)
  1283.                     losing++;
  1284.                 break;
  1285.  
  1286.             /* JF these are out of order.  We could put them
  1287.                in order if we were willing to put up with
  1288.                bunches of #ifdef m68851s in the code */
  1289. #ifdef m68851
  1290.             /* Memory addressing mode used by pflushr */
  1291.             case '|':
  1292.                 if(opP->mode==MSCR || opP->mode==DREG ||
  1293.  opP->mode==AREG || opP->mode==REGLST)
  1294.                     losing++;
  1295.                 break;
  1296.  
  1297.             case 'f':
  1298.                 if (opP->mode != MSCR || (opP->reg != SFC && opP->reg != DFC))
  1299.                     losing++;
  1300.                 break;
  1301.  
  1302.             case 'P':
  1303.                 if (opP->mode != MSCR || (opP->reg != TC && opP->reg != CAL &&
  1304.                     opP->reg != VAL && opP->reg != SCC && opP->reg != AC))
  1305.                     losing++;
  1306.                 break;
  1307.  
  1308.             case 'V':
  1309.                 if (opP->reg != VAL)
  1310.                     losing++;
  1311.                 break;
  1312.  
  1313.             case 'W':
  1314.                 if (opP->mode != MSCR || (opP->reg != DRP && opP->reg != SRP &&
  1315.                     opP->reg != CRP))
  1316.                     losing++;
  1317.                 break;
  1318.  
  1319.             case 'X':
  1320.                 if (opP->mode != MSCR ||
  1321.                     (!(opP->reg >= BAD && opP->reg <= BAD+7) &&
  1322.                      !(opP->reg >= BAC && opP->reg <= BAC+7)))
  1323.                     losing++;
  1324.                 break;
  1325.  
  1326.             case 'Y':
  1327.                 if (opP->reg != PSR)
  1328.                     losing++;
  1329.                 break;
  1330.  
  1331.             case 'Z':
  1332.                 if (opP->reg != PCSR)
  1333.                     losing++;
  1334.                 break;
  1335. #endif
  1336.             default:
  1337.                 as_fatal("Internal error:  Operand mode %c unknown",*s);
  1338.             }
  1339.         }
  1340.         if(!losing)
  1341.             break;
  1342.         opcode=opcode->m_next;
  1343.         if(!opcode) {        /* Fell off the end */
  1344.             the_ins.error="instruction/operands mismatch";
  1345.             return;
  1346.         }
  1347.         losing=0;
  1348.     }
  1349.     the_ins.args=opcode->m_operands;
  1350.     the_ins.numargs=opcode->m_opnum;
  1351.     the_ins.numo=opcode->m_codenum;
  1352.     the_ins.opcode[0]=getone(opcode);
  1353.     the_ins.opcode[1]=gettwo(opcode);
  1354.  
  1355.     for(s=the_ins.args,opP= &the_ins.operands[0];*s;s+=2,opP++) {
  1356.             /* This switch is a doozy.
  1357.                What the first step; its a big one! */
  1358.         switch(s[0]) {
  1359.  
  1360.         case '*':
  1361.         case '~':
  1362.         case '%':
  1363.         case ';':
  1364.         case '@':
  1365.         case '!':
  1366.         case '&':
  1367.         case '$':
  1368.         case '?':
  1369.         case '/':
  1370. #ifdef m68851
  1371.         case '|':
  1372. #endif
  1373.             switch(opP->mode) {
  1374.             case IMMED:
  1375.                 tmpreg=0x3c;    /* 7.4 */
  1376.                 if(index("bwl",s[1])) nextword=get_num(opP->con1,80);
  1377.                 else nextword=nextword=get_num(opP->con1,0);
  1378.                 if(isvar(opP->con1))
  1379.                     add_fix(s[1],opP->con1,0);
  1380.                 switch(s[1]) {
  1381.                 case 'b':
  1382.                     if(!isbyte(nextword))
  1383.                         opP->error="operand out of range";
  1384.                     addword(nextword);
  1385.                     baseo=0;
  1386.                     break;
  1387.                 case 'w':
  1388.                     if(!isword(nextword))
  1389.                         opP->error="operand out of range";
  1390.                     addword(nextword);
  1391.                     baseo=0;
  1392.                     break;
  1393.                 case 'l':
  1394.                     addword(nextword>>16);
  1395.                     addword(nextword);
  1396.                     baseo=0;
  1397.                     break;
  1398.  
  1399.                 case 'f':
  1400.                     baseo=2;
  1401.                     outro=8;
  1402.                     break;
  1403.                 case 'F':
  1404.                     baseo=4;
  1405.                     outro=11;
  1406.                     break;
  1407.                 case 'x':
  1408.                     baseo=6;
  1409.                     outro=15;
  1410.                     break;
  1411.                 case 'p':
  1412.                     baseo=6;
  1413.                     outro= -1;
  1414.                     break;
  1415.                 default:
  1416.                     as_fatal("Internal error:  Can't decode %c%c",*s,s[1]);
  1417.                 }
  1418.                 if(!baseo)
  1419.                     break;
  1420.  
  1421.                 /* We gotta put out some float */
  1422.                 if(seg(opP->con1)!=SEG_BIG) {
  1423.                     int_to_gen(nextword);
  1424.                     gen_to_words(words,baseo,(long int)outro);
  1425.                     for(wordp=words;baseo--;wordp++)
  1426.                         addword(*wordp);
  1427.                     break;
  1428.                 }        /* Its BIG */
  1429.                 if(offs(opP->con1)>0) {
  1430.                     as_warn("Bignum assumed to be binary bit-pattern");
  1431.                     if(offs(opP->con1)>baseo) {
  1432.                         as_warn("Bignum too big for %c format; truncated",s[1]);
  1433.                         offs(opP->con1)=baseo;
  1434.                     }
  1435.                     baseo-=offs(opP->con1);
  1436.                     for(wordp=generic_bignum+offs(opP->con1)-1;offs(opP->con1)--;--wordp)
  1437.                         addword(*wordp);
  1438.                     while(baseo--)
  1439.                         addword(0);
  1440.                     break;
  1441.                 }
  1442.                 gen_to_words(words,baseo,(long int)outro);
  1443.                 for(wordp=words;baseo--;wordp++)
  1444.                     addword(*wordp);
  1445.                 break;
  1446.             case DREG:
  1447.                 tmpreg=opP->reg-DATA; /* 0.dreg */
  1448.                 break;
  1449.             case AREG:
  1450.                 tmpreg=0x08+opP->reg-ADDR; /* 1.areg */
  1451.                 break;
  1452.             case AINDR:
  1453.                 tmpreg=0x10+opP->reg-ADDR; /* 2.areg */
  1454.                 break;
  1455.             case ADEC:
  1456.                 tmpreg=0x20+opP->reg-ADDR; /* 4.areg */
  1457.                 break;
  1458.             case AINC:
  1459.                 tmpreg=0x18+opP->reg-ADDR; /* 3.areg */
  1460.                 break;
  1461.             case AOFF:
  1462.  
  1463.                 nextword=get_num(opP->con1,80);
  1464.                 /* Force into index mode.  Hope this works */
  1465.  
  1466.                 /* We do the first bit for 32-bit displacements,
  1467.                    and the second bit for 16 bit ones.  It is
  1468.                    possible that we should make the default be
  1469.                    WORD instead of LONG, but I think that'd
  1470.                    break GCC, so we put up with a little
  1471.                    inefficiency for the sake of working output.
  1472.                  */
  1473.  
  1474.                 if(   !issword(nextword)
  1475.                    || (   isvar(opP->con1)
  1476.                        && (  (   opP->con1->e_siz==0
  1477.                           && flagseen['l']==0)
  1478.                        || opP->con1->e_siz==3))) {
  1479.  
  1480.                     if(opP->reg==PC)
  1481.                         tmpreg=0x3B;    /* 7.3 */
  1482.                     else
  1483.                         tmpreg=0x30+opP->reg-ADDR;    /* 6.areg */
  1484.                     if(isvar(opP->con1)) {
  1485.                         if(opP->reg==PC) {
  1486.                                add_frag(adds(opP->con1),
  1487.                              offs(opP->con1),
  1488.                              TAB(PCLEA,SZ_UNDEF));
  1489.                             break;
  1490.                         } else {
  1491.                             addword(0x0170);
  1492.                             add_fix('l',opP->con1,1);
  1493.                         }
  1494.                     } else
  1495.                         addword(0x0170);
  1496.                     addword(nextword>>16);
  1497.                 } else {
  1498.                     if(opP->reg==PC)
  1499.                         tmpreg=0x3A; /* 7.2 */
  1500.                     else
  1501.                         tmpreg=0x28+opP->reg-ADDR; /* 5.areg */
  1502.  
  1503.                     if(isvar(opP->con1)) {
  1504.                         if(opP->reg==PC) {
  1505.                             add_fix('w',opP->con1,1);
  1506.                         } else
  1507.                             add_fix('w',opP->con1,0);
  1508.                         }
  1509.                 }
  1510.                 addword(nextword);
  1511.                 break;
  1512.             case AINDX:
  1513.             case APODX:
  1514.             case AMIND:
  1515.             case APRDX:
  1516.                 nextword=0;
  1517.                 baseo=get_num(opP->con1,80);
  1518.                 outro=get_num(opP->con2,80);
  1519.                     /* Figure out the 'addressing mode' */
  1520.                     /* Also turn on the BASE_DISABLE bit, if needed */
  1521.                 if(opP->reg==PC || opP->reg==ZPC) {
  1522.                     tmpreg=0x3b; /* 7.3 */
  1523.                     if(opP->reg==ZPC)
  1524.                         nextword|=0x80;
  1525.                 } else if(opP->reg==FAIL) {
  1526.                     nextword|=0x80;
  1527.                     tmpreg=0x30;    /* 6.garbage */
  1528.                 } else tmpreg=0x30+opP->reg-ADDR; /* 6.areg */
  1529.  
  1530.                 siz1= (opP->con1) ? opP->con1->e_siz : 0;
  1531.                 siz2= (opP->con2) ? opP->con2->e_siz : 0;
  1532.  
  1533.                     /* Index register stuff */
  1534.                 if(opP->ireg>=DATA+0 && opP->ireg<=ADDR+7) {
  1535.                     nextword|=(opP->ireg-DATA)<<12;
  1536.  
  1537.                     if(opP->isiz==0 || opP->isiz==3)
  1538.                         nextword|=0x800;
  1539.                     switch(opP->imul) {
  1540.                     case 1: break;
  1541.                     case 2: nextword|=0x200; break;
  1542.                     case 4: nextword|=0x400; break;
  1543.                     case 8: nextword|=0x600; break;
  1544.                     default: abort();
  1545.                     }
  1546.                         /* IF its simple,
  1547.                            GET US OUT OF HERE! */
  1548.  
  1549.                         /* Must be INDEX, with an index
  1550.                            register.  Address register
  1551.                            cannot be ZERO-PC, and either
  1552.                            :b was forced, or we know
  1553.                            it will fit */
  1554.                     if(   opP->mode==AINDX
  1555.                        && opP->reg!=FAIL
  1556.                        && opP->reg!=ZPC
  1557.                        && (   siz1==1
  1558.                            || (   issbyte(baseo)
  1559.                            && !isvar(opP->con1)))) {
  1560.                         nextword +=baseo&0xff;
  1561.                         addword(nextword);
  1562.                         if(isvar(opP->con1))
  1563.                             add_fix('B',opP->con1,0);
  1564.                         break;
  1565.                     }
  1566.                 } else
  1567.                     nextword|=0x40;    /* No index reg */
  1568.  
  1569.                     /* It aint simple */
  1570.                 nextword|=0x100;
  1571.                     /* If the guy specified a width, we assume that
  1572.                        it is wide enough.  Maybe it isn't.  Ifso, we lose
  1573.                      */
  1574.                 switch(siz1) {
  1575.                 case 0:
  1576.                     if(isvar(opP->con1) || !issword(baseo)) {
  1577.                         siz1=3;
  1578.                         nextword|=0x30;
  1579.                     } else if(baseo==0)
  1580.                         nextword|=0x10;
  1581.                     else {    
  1582.                         nextword|=0x20;
  1583.                         siz1=2;
  1584.                     }
  1585.                     break;
  1586.                 case 1:
  1587.                     as_warn("Byte dispacement won't work.  Defaulting to :w");
  1588.                 case 2:
  1589.                     nextword|=0x20;
  1590.                     break;
  1591.                 case 3:
  1592.                     nextword|=0x30;
  1593.                     break;
  1594.                 }
  1595.  
  1596.                     /* Figure out innner displacement stuff */
  1597.                 if(opP->mode!=AINDX) {
  1598.                     switch(siz2) {
  1599.                     case 0:
  1600.                         if(isvar(opP->con2) || !issword(outro)) {
  1601.                             siz2=3;
  1602.                             nextword|=0x3;
  1603.                         } else if(outro==0)
  1604.                             nextword|=0x1;
  1605.                         else {    
  1606.                             nextword|=0x2;
  1607.                             siz2=2;
  1608.                         }
  1609.                         break;
  1610.                     case 1:
  1611.                         as_warn("Byte dispacement won't work.  Defaulting to :w");
  1612.                     case 2:
  1613.                         nextword|=0x2;
  1614.                         break;
  1615.                     case 3:
  1616.                         nextword|=0x3;
  1617.                         break;
  1618.                     }
  1619.                     if(opP->mode==APODX) nextword|=0x04;
  1620.                     else if(opP->mode==AMIND) nextword|=0x40;
  1621.                 }
  1622.                 addword(nextword);
  1623.  
  1624.                 if(isvar(opP->con1)) {
  1625.                     if(opP->reg==PC || opP->reg==ZPC) {
  1626.                         add_fix(siz1==3 ? 'l' : 'w',opP->con1,1);
  1627.                         opP->con1->e_exp.X_add_number+=6;
  1628.                     } else
  1629.                         add_fix(siz1==3 ? 'l' : 'w',opP->con1,0);
  1630.                 }
  1631.                 if(siz1==3)
  1632.                     addword(baseo>>16);
  1633.                 if(siz1)
  1634.                     addword(baseo);
  1635.  
  1636.                 if(isvar(opP->con2)) {
  1637.                     if(opP->reg==PC || opP->reg==ZPC) {
  1638.                         add_fix(siz2==3 ? 'l' : 'w',opP->con2,1);
  1639.                         opP->con1->e_exp.X_add_number+=6;
  1640.                     } else
  1641.                         add_fix(siz2==3 ? 'l' : 'w',opP->con2,0);
  1642.                 }
  1643.                 if(siz2==3)
  1644.                     addword(outro>>16);
  1645.                 if(siz2)
  1646.                     addword(outro);
  1647.  
  1648.                 break;
  1649.  
  1650.             case ABSL:
  1651.                 nextword=get_num(opP->con1,80);
  1652.                 switch(opP->con1->e_siz) {
  1653.                 default:
  1654.                     as_warn("Unknown size for absolute reference");
  1655.                 case 0:
  1656.                     if(!isvar(opP->con1) && issword(offs(opP->con1))) {
  1657.                         tmpreg=0x38; /* 7.0 */
  1658.                         addword(nextword);
  1659.                         break;
  1660.                     }
  1661.                     /* Don't generate pc relative code
  1662.                        on 68010 and 68000 */
  1663.                     if(isvar(opP->con1) &&
  1664.                        !subs(opP->con1) &&
  1665.                        seg(opP->con1)==SEG_TEXT &&
  1666.                        now_seg==SEG_TEXT &&
  1667.                        flagseen['m']==0 &&
  1668.                         !index("~%&$?", s[0])) {
  1669.                         tmpreg=0x3A; /* 7.2 */
  1670.                         add_frag(adds(opP->con1),
  1671.                              offs(opP->con1),
  1672.                              TAB(PCREL,SZ_UNDEF));
  1673.                         break;
  1674.                     }
  1675.                 case 3:        /* Fall through into long */
  1676.                     if(isvar(opP->con1))
  1677.                         add_fix('l',opP->con1,0);
  1678.  
  1679.                     tmpreg=0x39;    /* 7.1 mode */
  1680.                     addword(nextword>>16);
  1681.                     addword(nextword);
  1682.                     break;
  1683.  
  1684.                 case 2:        /* Word */
  1685.                     if(isvar(opP->con1))
  1686.                         add_fix('w',opP->con1,0);
  1687.  
  1688.                     tmpreg=0x38;    /* 7.0 mode */
  1689.                     addword(nextword);
  1690.                     break;
  1691.                 }
  1692.                 break;
  1693.             case MSCR:
  1694.             default:
  1695.                 as_bad("unknown/incorrect operand");
  1696.                 /* abort(); */
  1697.             }
  1698.             install_gen_operand(s[1],tmpreg);
  1699.             break;
  1700.  
  1701.         case '#':
  1702.         case '^':
  1703.             switch(s[1]) {    /* JF: I hate floating point! */
  1704.             case 'j':
  1705.                 tmpreg=70;
  1706.                 break;
  1707.             case '8':
  1708.                 tmpreg=20;
  1709.                 break;
  1710.             case 'C':
  1711.                 tmpreg=50;
  1712.                 break;
  1713.             case '3':
  1714.             default:
  1715.                 tmpreg=80;
  1716.                 break;
  1717.             }
  1718.             tmpreg=get_num(opP->con1,tmpreg);
  1719.             if(isvar(opP->con1))
  1720.                 add_fix(s[1],opP->con1,0);
  1721.             switch(s[1]) {
  1722.             case 'b':    /* Danger:  These do no check for
  1723.                        certain types of overflow.
  1724.                        user beware! */
  1725.                 if(!isbyte(tmpreg))
  1726.                     opP->error="out of range";
  1727.                 insop(tmpreg);
  1728.                 if(isvar(opP->con1))
  1729.                     the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
  1730.                 break;
  1731.             case 'w':
  1732.                 if(!isword(tmpreg))
  1733.                     opP->error="out of range";
  1734.                 insop(tmpreg);
  1735.                 if(isvar(opP->con1))
  1736.                     the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
  1737.                 break;
  1738.             case 'l':
  1739.                 insop(tmpreg);        /* Because of the way insop works, we put these two out backwards */
  1740.                 insop(tmpreg>>16);
  1741.                 if(isvar(opP->con1))
  1742.                     the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
  1743.                 break;
  1744.             case '3':
  1745.                 tmpreg&=0xFF;
  1746.             case '8':
  1747.             case 'C':
  1748.                 install_operand(s[1],tmpreg);
  1749.                 break;
  1750.             default:
  1751.                 as_fatal("Internal error:  Unknown mode #%c",s[1]);
  1752.             }
  1753.             break;
  1754.  
  1755.         case '+':
  1756.         case '-':
  1757.         case 'A':
  1758.             install_operand(s[1],opP->reg-ADDR);
  1759.             break;
  1760.  
  1761.         case 'B':
  1762.             tmpreg=get_num(opP->con1,80);
  1763.             switch(s[1]) {
  1764.             case 'g':
  1765.                 if(opP->con1->e_siz) {    /* Deal with fixed size stuff by hand */
  1766.                     switch(opP->con1->e_siz) {
  1767.                     case 1:
  1768.                         add_fix('b',opP->con1,1);
  1769.                         break;
  1770.                     case 2:
  1771.                         add_fix('w',opP->con1,1);
  1772.                         addword(0);
  1773.                         break;
  1774.                     case 3:
  1775.                         add_fix('l',opP->con1,1);
  1776.                         addword(0);
  1777.                         addword(0);
  1778.                         break;
  1779.                     default:
  1780.                         as_fatal("Bad size for expression %d",opP->con1->e_siz);
  1781.                     }
  1782.                 } else if(subs(opP->con1)) {
  1783.                         /* We can't relax it */
  1784.                     the_ins.opcode[the_ins.numo-1]|=0xff;
  1785.                     add_fix('l',opP->con1,1);
  1786.                     addword(0);
  1787.                     addword(0);
  1788.                 } else if(adds(opP->con1)) {
  1789.                     if (flagseen['m'] && 
  1790.                         (the_ins.opcode[0] >= 0x6200) &&
  1791.                         (the_ins.opcode[0] <= 0x6f00)) {
  1792.                       add_frag(adds(opP->con1),offs(opP->con1),TAB(BCC68000,SZ_UNDEF));
  1793.                     } else {
  1794.                         add_frag(adds(opP->con1),offs(opP->con1),TAB(BRANCH,SZ_UNDEF));
  1795.                     }
  1796.                 } else {
  1797.                     /* JF:  This is the WRONG thing to do
  1798.                     add_frag((symbolS *)0,offs(opP->con1),TAB(BRANCH,BYTE)); */
  1799.                     the_ins.opcode[the_ins.numo-1]|=0xff;
  1800.                     offs(opP->con1)+=4;
  1801.                     add_fix('l',opP->con1,1);
  1802.                     addword(0);
  1803.                     addword(0);
  1804.                 }
  1805.                 break;
  1806.             case 'w':
  1807.                 if(isvar(opP->con1)) {
  1808.                     /* check for DBcc instruction */
  1809.                     if ((the_ins.opcode[0] & 0xf0f8) ==0x50c8) {
  1810.                         /* size varies if patch */
  1811.                         /* needed for long form */
  1812.                         add_frag(adds(opP->con1),offs(opP->con1),TAB(DBCC,SZ_UNDEF));
  1813.                         break;
  1814.                     }
  1815.  
  1816.                         /* Don't ask! */
  1817.                     opP->con1->e_exp.X_add_number+=2;
  1818.                     add_fix('w',opP->con1,1);
  1819.                 }
  1820.                 addword(0);
  1821.                 break;
  1822.             case 'c':
  1823.                 if(opP->con1->e_siz) {
  1824.                     switch(opP->con1->e_siz) {
  1825.                     case 2:
  1826.                         add_fix('w',opP->con1,1)
  1827.                         addword(0);
  1828.                         break;
  1829.                     case 3:
  1830.                         the_ins.opcode[the_ins.numo-1]|=0x40;
  1831.                         add_fix('l',opP->con1,1);
  1832.                         addword(0);
  1833.                         addword(0);
  1834.                         break;
  1835.                     default:
  1836.                         as_bad("Bad size for offset, must be word or long");
  1837.                         break;
  1838.                     }
  1839.                 } else if(subs(opP->con1)) {
  1840.                     add_fix('l',opP->con1,1);
  1841.                     add_frag((symbolS *)0,(long)0,TAB(FBRANCH,LONG));
  1842.                 } else if(adds(opP->con1)) {
  1843.                     add_frag(adds(opP->con1),offs(opP->con1),TAB(FBRANCH,SZ_UNDEF));
  1844.                 } else {
  1845.                     /* add_frag((symbolS *)0,offs(opP->con1),TAB(FBRANCH,SHORT)); */
  1846.                     the_ins.opcode[the_ins.numo-1]|=0x40;
  1847.                     add_fix('l',opP->con1,1);
  1848.                     addword(0);
  1849.                     addword(4);
  1850.                 }
  1851.                 break;
  1852.             default:
  1853.                 as_fatal("Internal error:  operand type B%c unknown",s[1]);
  1854.             }
  1855.             break;
  1856.  
  1857.         case 'C':        /* Ignore it */
  1858.             break;
  1859.  
  1860.         case 'd':        /* JF this is a kludge */
  1861.             if(opP->mode==AOFF) {
  1862.                 install_operand('s',opP->reg-ADDR);
  1863.             } else {
  1864.                 char *tmpP;
  1865.  
  1866.                 tmpP=opP->con1->e_end-2;
  1867.                 opP->con1->e_beg++;
  1868.                 opP->con1->e_end-=4;    /* point to the , */
  1869.                 baseo=m68k_reg_parse(&tmpP);
  1870.                 if(baseo<ADDR+0 || baseo>ADDR+7) {
  1871.                     as_bad("Unknown address reg, using A0");
  1872.                     baseo=0;
  1873.                 } else baseo-=ADDR;
  1874.                 install_operand('s',baseo);
  1875.             }
  1876.             tmpreg=get_num(opP->con1,80);
  1877.             if(!issword(tmpreg)) {
  1878.                 as_warn("Expression out of range, using 0");
  1879.                 tmpreg=0;
  1880.             }
  1881.             addword(tmpreg);
  1882.             break;
  1883.  
  1884.         case 'D':
  1885.             install_operand(s[1],opP->reg-DATA);
  1886.             break;
  1887.  
  1888.         case 'F':
  1889.             install_operand(s[1],opP->reg-FPREG);
  1890.             break;
  1891.  
  1892.         case 'I':
  1893.             tmpreg=1+opP->reg-COPNUM;
  1894.             if(tmpreg==8)
  1895.                 tmpreg=0;
  1896.             install_operand(s[1],tmpreg);
  1897.             break;
  1898.  
  1899.         case 'J':        /* JF foo */
  1900.             switch(opP->reg) {
  1901.             case SFC:
  1902.                 tmpreg=0;
  1903.                 break;
  1904.             case DFC:
  1905.                 tmpreg=0x001;
  1906.                 break;
  1907.             case CACR:
  1908.                 tmpreg=0x002;
  1909.                 break;
  1910.             case USP:
  1911.                 tmpreg=0x800;
  1912.                 break;
  1913.             case VBR:
  1914.                 tmpreg=0x801;
  1915.                 break;
  1916.             case CAAR:
  1917.                 tmpreg=0x802;
  1918.                 break;
  1919.             case MSP:
  1920.                 tmpreg=0x803;
  1921.                 break;
  1922.             case ISP:
  1923.                 tmpreg=0x804;
  1924.                 break;
  1925.             default:
  1926.                 abort();
  1927.             }
  1928.             install_operand(s[1],tmpreg);
  1929.             break;
  1930.  
  1931.         case 'k':
  1932.             tmpreg=get_num(opP->con1,55);
  1933.             install_operand(s[1],tmpreg&0x7f);
  1934.             break;
  1935.  
  1936.         case 'l':
  1937.             tmpreg=opP->reg;
  1938.             if(s[1]=='w') {
  1939.                 if(tmpreg&0x7FF0000)
  1940.                     as_bad("Floating point register in register list");
  1941.                 insop(reverse_16_bits(tmpreg));
  1942.             } else {
  1943.                 if(tmpreg&0x700FFFF)
  1944.                     as_bad("Wrong register in floating-point reglist");
  1945.                 install_operand(s[1],reverse_8_bits(tmpreg>>16));
  1946.             }
  1947.             break;
  1948.  
  1949.         case 'L':
  1950.             tmpreg=opP->reg;
  1951.             if(s[1]=='w') {
  1952.                 if(tmpreg&0x7FF0000)
  1953.                     as_bad("Floating point register in register list");
  1954.                 insop(tmpreg);
  1955.             } else if(s[1]=='8') {
  1956.                 if(tmpreg&0x0FFFFFF)
  1957.                     as_bad("incorrect register in reglist");
  1958.                 install_operand(s[1],tmpreg>>24);
  1959.             } else {
  1960.                 if(tmpreg&0x700FFFF)
  1961.                     as_bad("wrong register in floating-point reglist");
  1962.                 else
  1963.                     install_operand(s[1],tmpreg>>16);
  1964.             }
  1965.             break;
  1966.  
  1967.         case 'M':
  1968.             install_operand(s[1],get_num(opP->con1,60));
  1969.             break;
  1970.  
  1971.         case 'O':
  1972.             tmpreg= (opP->mode==DREG)
  1973.                 ? 0x20+opP->reg-DATA
  1974.                 : (get_num(opP->con1,40)&0x1F);
  1975.             install_operand(s[1],tmpreg);
  1976.             break;
  1977.  
  1978.         case 'Q':
  1979.             tmpreg=get_num(opP->con1,10);
  1980.             if(tmpreg==8)
  1981.                 tmpreg=0;
  1982.             install_operand(s[1],tmpreg);
  1983.             break;
  1984.  
  1985.         case 'R':
  1986.             /* This depends on the fact that ADDR registers are
  1987.                eight more than their corresponding DATA regs, so
  1988.                the result will have the ADDR_REG bit set */
  1989.             install_operand(s[1],opP->reg-DATA);
  1990.             break;
  1991.  
  1992.         case 's':
  1993.             if(opP->reg==FPI) tmpreg=0x1;
  1994.             else if(opP->reg==FPS) tmpreg=0x2;
  1995.             else if(opP->reg==FPC) tmpreg=0x4;
  1996.             else abort();
  1997.             install_operand(s[1],tmpreg);
  1998.             break;
  1999.  
  2000.         case 'S':    /* Ignore it */
  2001.             break;
  2002.  
  2003.         case 'T':
  2004.             install_operand(s[1],get_num(opP->con1,30));
  2005.             break;
  2006.  
  2007.         case 'U':    /* Ignore it */
  2008.             break;
  2009.  
  2010. #ifdef m68851
  2011.             /* JF: These are out of order, I fear. */
  2012.         case 'f':
  2013.             switch (opP->reg) {
  2014.             case SFC:
  2015.                 tmpreg=0;
  2016.                 break;
  2017.             case DFC:
  2018.                 tmpreg=1;
  2019.                 break;
  2020.             default:
  2021.                 abort();
  2022.             }
  2023.             install_operand(s[1],tmpreg);
  2024.             break;
  2025.  
  2026.         case 'P':
  2027.             switch(opP->reg) {
  2028.             case TC:
  2029.                 tmpreg=0;
  2030.                 break;
  2031.             case CAL:
  2032.                 tmpreg=4;
  2033.                 break;
  2034.             case VAL:
  2035.                 tmpreg=5;
  2036.                 break;
  2037.             case SCC:
  2038.                 tmpreg=6;
  2039.                 break;
  2040.             case AC:
  2041.                 tmpreg=7;
  2042.                 break;
  2043.             default:
  2044.                 abort();
  2045.             }
  2046.             install_operand(s[1],tmpreg);
  2047.             break;
  2048.  
  2049.         case 'V':
  2050.             if (opP->reg == VAL)
  2051.                 break;
  2052.             abort();
  2053.  
  2054.         case 'W':
  2055.             switch(opP->reg) {
  2056.  
  2057.             case DRP:
  2058.                 tmpreg=1;
  2059.                 break;
  2060.             case SRP:
  2061.                 tmpreg=2;
  2062.                 break;
  2063.             case CRP:
  2064.                 tmpreg=3;
  2065.                 break;
  2066.             default:
  2067.                 abort();
  2068.             }
  2069.             install_operand(s[1],tmpreg);
  2070.             break;
  2071.  
  2072.         case 'X':
  2073.             switch (opP->reg) {
  2074.             case BAD: case BAD+1: case BAD+2: case BAD+3:
  2075.             case BAD+4: case BAD+5: case BAD+6: case BAD+7:
  2076.                 tmpreg = (4 << 10) | ((opP->reg - BAD) << 2);
  2077.                 break;
  2078.  
  2079.             case BAC: case BAC+1: case BAC+2: case BAC+3:
  2080.             case BAC+4: case BAC+5: case BAC+6: case BAC+7:
  2081.                 tmpreg = (5 << 10) | ((opP->reg - BAC) << 2);
  2082.                 break;
  2083.  
  2084.             default:
  2085.                 abort();
  2086.             }
  2087.             install_operand(s[1], tmpreg);
  2088.             break;
  2089.         case 'Y':
  2090.             if (opP->reg == PSR)
  2091.                 break;
  2092.             abort();
  2093.  
  2094.         case 'Z':
  2095.             if (opP->reg == PCSR)
  2096.                 break;
  2097.             abort();
  2098. #endif /* m68851 */
  2099.         default:
  2100.             as_fatal("Internal error:  Operand type %c unknown",s[0]);
  2101.         }
  2102.     }
  2103.     /* By the time whe get here (FINALLY) the_ins contains the complete
  2104.        instruction, ready to be emitted. . . */
  2105. }
  2106.  
  2107. int
  2108. get_regs(i,str,opP)
  2109. struct m68k_op *opP;
  2110. char *str;
  2111. {
  2112.     /*                 26, 25, 24, 23-16,  15-8, 0-7 */
  2113.     /* Low order 24 bits encoded fpc,fps,fpi,fp7-fp0,a7-a0,d7-d0 */
  2114.     unsigned long int cur_regs = 0;
  2115.     int    reg1,
  2116.         reg2;
  2117.  
  2118. #define ADD_REG(x)    {     if(x==FPI) cur_regs|=(1<<24);\
  2119.              else if(x==FPS) cur_regs|=(1<<25);\
  2120.              else if(x==FPC) cur_regs|=(1<<26);\
  2121.              else cur_regs|=(1<<(x-1));  }
  2122.  
  2123.     reg1=i;
  2124.     for(;;) {
  2125.         if(*str=='/') {
  2126.             ADD_REG(reg1);
  2127.             str++;
  2128.         } else if(*str=='-') {
  2129.             str++;
  2130.             reg2=m68k_reg_parse(&str);
  2131.             if(reg2<DATA || reg2>=FPREG+8 || reg1==FPI || reg1==FPS || reg1==FPC) {
  2132.                 opP->error="unknown register in register list";
  2133.                 return FAIL;
  2134.             }
  2135.             while(reg1<=reg2) {
  2136.                 ADD_REG(reg1);
  2137.                 reg1++;
  2138.             }
  2139.             if(*str=='\0')
  2140.                 break;
  2141.         } else if(*str=='\0') {
  2142.             ADD_REG(reg1);
  2143.             break;
  2144.         } else {
  2145.             opP->error="unknow character in register list";
  2146.             return FAIL;
  2147.         }
  2148. /* DJA -- Bug Fix.  Did't handle d1-d2/a1 until the following instruction was added */
  2149.         if (*str=='/')
  2150.           str ++;
  2151.         reg1=m68k_reg_parse(&str);
  2152.         if((reg1<DATA || reg1>=FPREG+8) && !(reg1==FPI || reg1==FPS || reg1==FPC)) {
  2153.             opP->error="unknown register in register list";
  2154.             return FAIL;
  2155.         }
  2156.     }
  2157.     opP->reg=cur_regs;
  2158.     return OK;
  2159. }
  2160.  
  2161. int
  2162. reverse_16_bits(in)
  2163. int in;
  2164. {
  2165.     int out=0;
  2166.     int n;
  2167.  
  2168.     static int mask[16] = {
  2169. 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
  2170. 0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000
  2171.     };
  2172.     for(n=0;n<16;n++) {
  2173.         if(in&mask[n])
  2174.             out|=mask[15-n];
  2175.     }
  2176.     return out;
  2177. }
  2178.  
  2179. int
  2180. reverse_8_bits(in)
  2181. int in;
  2182. {
  2183.     int out=0;
  2184.     int n;
  2185.  
  2186.     static int mask[8] = {
  2187. 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
  2188.     };
  2189.  
  2190.     for(n=0;n<8;n++) {
  2191.         if(in&mask[n])
  2192.             out|=mask[7-n];
  2193.     }
  2194.     return out;
  2195. }
  2196.  
  2197. void
  2198. install_operand(mode,val)
  2199. int mode;
  2200. int val;
  2201. {
  2202.     switch(mode) {
  2203.     case 's':
  2204.         the_ins.opcode[0]|=val & 0xFF;    /* JF FF is for M kludge */
  2205.         break;
  2206.     case 'd':
  2207.         the_ins.opcode[0]|=val<<9;
  2208.         break;
  2209.     case '1':
  2210.         the_ins.opcode[1]|=val<<12;
  2211.         break;
  2212.     case '2':
  2213.         the_ins.opcode[1]|=val<<6;
  2214.         break;
  2215.     case '3':
  2216.         the_ins.opcode[1]|=val;
  2217.         break;
  2218.     case '4':
  2219.         the_ins.opcode[2]|=val<<12;
  2220.         break;
  2221.     case '5':
  2222.         the_ins.opcode[2]|=val<<6;
  2223.         break;
  2224.     case '6':
  2225.             /* DANGER!  This is a hack to force cas2l and cas2w cmds
  2226.                to be three words long! */
  2227.         the_ins.numo++;
  2228.         the_ins.opcode[2]|=val;
  2229.         break;
  2230.     case '7':
  2231.         the_ins.opcode[1]|=val<<7;
  2232.         break;
  2233.     case '8':
  2234.         the_ins.opcode[1]|=val<<10;
  2235.         break;
  2236. #ifdef m68851
  2237.     case '9':
  2238.         the_ins.opcode[1]|=val<<5;
  2239.         break;
  2240. #endif
  2241.  
  2242.     case 't':
  2243.         the_ins.opcode[1]|=(val<<10)|(val<<7);
  2244.         break;
  2245.     case 'D':
  2246.         the_ins.opcode[1]|=(val<<12)|val;
  2247.         break;
  2248.     case 'g':
  2249.         the_ins.opcode[0]|=val=0xff;
  2250.         break;
  2251.     case 'i':
  2252.         the_ins.opcode[0]|=val<<9;
  2253.         break;
  2254.     case 'C':
  2255.         the_ins.opcode[1]|=val;
  2256.         break;
  2257.     case 'j':
  2258.         the_ins.opcode[1]|=val;
  2259.         the_ins.numo++;        /* What a hack */
  2260.         break;
  2261.     case 'k':
  2262.         the_ins.opcode[1]|=val<<4;
  2263.         break;
  2264.     case 'b':
  2265.     case 'w':
  2266.     case 'l':
  2267.         break;
  2268.     case 'c':
  2269.     default:
  2270.         abort();
  2271.     }
  2272. }
  2273.  
  2274. void
  2275. install_gen_operand(mode,val)
  2276. int mode;
  2277. int val;
  2278. {
  2279.     switch(mode) {
  2280.     case 's':
  2281.         the_ins.opcode[0]|=val;
  2282.         break;
  2283.     case 'd':
  2284.             /* This is a kludge!!! */
  2285.         the_ins.opcode[0]|=(val&0x07)<<9|(val&0x38)<<3;
  2286.         break;
  2287.     case 'b':
  2288.     case 'w':
  2289.     case 'l':
  2290.     case 'f':
  2291.     case 'F':
  2292.     case 'x':
  2293.     case 'p':
  2294.         the_ins.opcode[0]|=val;
  2295.         break;
  2296.         /* more stuff goes here */
  2297.     default:
  2298.         abort();
  2299.     }
  2300. }
  2301.  
  2302. char *
  2303. crack_operand(str,opP)
  2304. register char *str;
  2305. register struct m68k_op *opP;
  2306. {
  2307.     register int parens;
  2308.     register int c;
  2309.     register char *beg_str;
  2310.  
  2311.     if(!str) {
  2312.         return str;
  2313.     }
  2314.     beg_str=str;
  2315.     for(parens=0;*str && (parens>0 || notend(str));str++) {
  2316.         if(*str=='(') parens++;
  2317.         else if(*str==')') {
  2318.             if(!parens) {        /* ERROR */
  2319.                 opP->error="Extra )";
  2320.                 return str;
  2321.             }
  2322.             --parens;
  2323.         }
  2324.     }
  2325.     if(!*str && parens) {        /* ERROR */
  2326.         opP->error="Missing )";
  2327.         return str;
  2328.     }
  2329.     c= *str;
  2330.     *str='\0';
  2331.     if(m68k_ip_op(beg_str,opP)==FAIL) {
  2332.         *str=c;
  2333.         return str;
  2334.     }
  2335.     *str=c;
  2336.     if(c=='}')
  2337.         c= *++str;        /* JF bitfield hack */
  2338.     if(c) {
  2339.         c= *++str;
  2340.         if(!c)
  2341.             as_bad("Missing operand");
  2342.     }
  2343.     return str;
  2344. }
  2345.  
  2346. /* See the comment up above where the #define notend(... is */
  2347. #if 0
  2348. notend(s)
  2349. char *s;
  2350. {
  2351.     if(*s==',') return 0;
  2352.     if(*s=='{' || *s=='}')
  2353.         return 0;
  2354.     if(*s!=':') return 1;
  2355.         /* This kludge here is for the division cmd, which is a kludge */
  2356.     if(index("aAdD#",s[1])) return 0;
  2357.     return 1;
  2358. }
  2359. #endif
  2360.  
  2361. /* This is the guts of the machine-dependent assembler.  STR points to a
  2362.    machine dependent instruction.  This funciton is supposed to emit
  2363.    the frags/bytes it assembles to.
  2364.  */
  2365. void
  2366. md_assemble(str)
  2367. char *str;
  2368. {
  2369.     char *er;
  2370.     short    *fromP;
  2371.     char    *toP;
  2372.     int    m,n;
  2373.     char    *to_beg_P;
  2374.     int    shorts_this_frag;
  2375.  
  2376.     bzero((char *)(&the_ins),sizeof(the_ins));    /* JF for paranoia sake */
  2377.     m68_ip(str);
  2378.     er=the_ins.error;
  2379.     if(!er) {
  2380.         for(n=the_ins.numargs;n;--n)
  2381.             if(the_ins.operands[n].error) {
  2382.                 er=the_ins.operands[n].error;
  2383.                 break;
  2384.             }
  2385.     }
  2386.     if(er) {
  2387.         as_bad("\"%s\" -- Statement '%s' ignored",er,str);
  2388.         return;
  2389.     }
  2390.  
  2391.     if(the_ins.nfrag==0) {    /* No frag hacking involved; just put it out */
  2392.         toP=frag_more(2*the_ins.numo);
  2393.         fromP= &the_ins.opcode[0];
  2394.         for(m=the_ins.numo;m;--m) {
  2395.             md_number_to_chars(toP,(long)(*fromP),2);
  2396.             toP+=2;
  2397.             fromP++;
  2398.         }
  2399.             /* put out symbol-dependent info */
  2400.         for(m=0;m<the_ins.nrel;m++) {
  2401.             switch(the_ins.reloc[m].wid) {
  2402.             case 'B':
  2403.                 n=1;
  2404.                 break;
  2405.             case 'b':
  2406.                 n=1;
  2407.                 break;
  2408.             case '3':
  2409.                 n=2;
  2410.                 break;
  2411.             case 'w':
  2412.                 n=2;
  2413.                 break;
  2414.             case 'l':
  2415.                 n=4;
  2416.                 break;
  2417.             default:
  2418.                 as_fatal("Don't know how to figure width of %c in md_assemble()",the_ins.reloc[m].wid);
  2419.             }
  2420.  
  2421.             fix_new(frag_now,
  2422.                 (toP-frag_now->fr_literal)-the_ins.numo*2+the_ins.reloc[m].n,
  2423.                 n,
  2424.                 the_ins.reloc[m].add,
  2425.                 the_ins.reloc[m].sub,
  2426.                 the_ins.reloc[m].off,
  2427.                 the_ins.reloc[m].pcrel);
  2428.         }
  2429.         return;
  2430.     }
  2431.  
  2432.         /* There's some frag hacking */
  2433.     for(n=0,fromP= &the_ins.opcode[0];n<the_ins.nfrag;n++) {
  2434.         int wid;
  2435.  
  2436.         if(n==0) wid=2*the_ins.fragb[n].fragoff;
  2437.         else wid=2*(the_ins.numo-the_ins.fragb[n-1].fragoff);
  2438.         toP=frag_more(wid);
  2439.         to_beg_P=toP;
  2440.         shorts_this_frag=0;
  2441.         for(m=wid/2;m;--m) {
  2442.             md_number_to_chars(toP,(long)(*fromP),2);
  2443.             toP+=2;
  2444.             fromP++;
  2445.             shorts_this_frag++;
  2446.         }
  2447.         for(m=0;m<the_ins.nrel;m++) {
  2448.             if((the_ins.reloc[m].n)>= 2*shorts_this_frag /* 2*the_ins.fragb[n].fragoff */) {
  2449.                 the_ins.reloc[m].n-= 2*shorts_this_frag /* 2*the_ins.fragb[n].fragoff */;
  2450.                 break;
  2451.             }
  2452.             wid=the_ins.reloc[m].wid;
  2453.             if(wid==0)
  2454.                 continue;
  2455.             the_ins.reloc[m].wid=0;
  2456.             wid = (wid=='b') ? 1 : (wid=='w') ? 2 : (wid=='l') ? 4 : 4000;
  2457.  
  2458.             fix_new(frag_now,
  2459.                 (toP-frag_now->fr_literal)-the_ins.numo*2+the_ins.reloc[m].n,
  2460.                 wid,
  2461.                 the_ins.reloc[m].add,
  2462.                 the_ins.reloc[m].sub,
  2463.                 the_ins.reloc[m].off,
  2464.                 the_ins.reloc[m].pcrel);
  2465.         }
  2466.         know(the_ins.fragb[n].fadd);
  2467.         (void)frag_var(rs_machine_dependent,10,0,(relax_substateT)(the_ins.fragb[n].fragty),
  2468.  the_ins.fragb[n].fadd,the_ins.fragb[n].foff,to_beg_P);
  2469.     }
  2470.     n=(the_ins.numo-the_ins.fragb[n-1].fragoff);
  2471.     shorts_this_frag=0;
  2472.     if(n) {
  2473.         toP=frag_more(n*sizeof(short));
  2474.         while(n--) {
  2475.             md_number_to_chars(toP,(long)(*fromP),2);
  2476.             toP+=2;
  2477.             fromP++;
  2478.             shorts_this_frag++;
  2479.         }
  2480.     }
  2481.     for(m=0;m<the_ins.nrel;m++) {
  2482.         int wid;
  2483.  
  2484.         wid=the_ins.reloc[m].wid;
  2485.         if(wid==0)
  2486.             continue;
  2487.         the_ins.reloc[m].wid=0;
  2488.         wid = (wid=='b') ? 1 : (wid=='w') ? 2 : (wid=='l') ? 4 : 4000;
  2489.  
  2490.         fix_new(frag_now,
  2491.             (the_ins.reloc[m].n + toP-frag_now->fr_literal)-/* the_ins.numo */ shorts_this_frag*2,
  2492.             wid,
  2493.             the_ins.reloc[m].add,
  2494.             the_ins.reloc[m].sub,
  2495.             the_ins.reloc[m].off,
  2496.             the_ins.reloc[m].pcrel);
  2497.     }
  2498. }
  2499.  
  2500. /* This function is called once, at assembler startup time.  This should
  2501.    set up all the tables, etc that the MD part of the assembler needs
  2502.  */
  2503. void
  2504. md_begin()
  2505. {
  2506. /*
  2507.  * md_begin -- set up hash tables with 68000 instructions.
  2508.  * similar to what the vax assembler does.  ---phr
  2509.  */
  2510.     /* RMS claims the thing to do is take the m68k-opcode.h table, and make
  2511.        a copy of it at runtime, adding in the information we want but isn't
  2512.        there.  I think it'd be better to have an awk script hack the table
  2513.        at compile time.  Or even just xstr the table and use it as-is.  But
  2514.        my lord ghod hath spoken, so we do it this way.  Excuse the ugly var
  2515.        names.  */
  2516.  
  2517.     register struct m68k_opcode *ins;
  2518.     register struct m68_incant *hack,
  2519.         *slak;
  2520.     register char *retval = 0;        /* empty string, or error msg text */
  2521.     register int i;
  2522.     register char c;
  2523.  
  2524.     if ((op_hash = hash_new()) == NULL)
  2525.         as_fatal("Virtual memory exhausted");
  2526.  
  2527.     obstack_begin(&robyn,4000);
  2528.     for (ins = m68k_opcodes; ins < endop; ins++) {
  2529.         hack=slak=(struct m68_incant *)obstack_alloc(&robyn,sizeof(struct m68_incant));
  2530.         do {
  2531.             slak->m_operands=ins->args;
  2532.             slak->m_opnum=strlen(slak->m_operands)/2;
  2533.             slak->m_opcode=ins->opcode;
  2534.                 /* This is kludgey */
  2535.             slak->m_codenum=((ins->match)&0xffffL) ? 2 : 1;
  2536.             if((ins+1)!=endop && !strcmp(ins->name,(ins+1)->name)) {
  2537.                 slak->m_next=(struct m68_incant *)
  2538. obstack_alloc(&robyn,sizeof(struct m68_incant));
  2539.                 ins++;
  2540.             } else
  2541.                 slak->m_next=0;
  2542.             slak=slak->m_next;
  2543.         } while(slak);
  2544.  
  2545.         retval = hash_insert (op_hash, ins->name,(char *)hack);
  2546.             /* Didn't his mommy tell him about null pointers? */
  2547.         if(retval && *retval)
  2548.             as_fatal("Internal Error:  Can't hash %s: %s",ins->name,retval);
  2549.     }
  2550.  
  2551.     for (i = 0; i < sizeof(mklower_table) ; i++)
  2552.         mklower_table[i] = (isupper(c = (char) i)) ? tolower(c) : c;
  2553.  
  2554.     for (i = 0 ; i < sizeof(notend_table) ; i++) {
  2555.         notend_table[i] = 0;
  2556.         alt_notend_table[i] = 0;
  2557.     }
  2558.     notend_table[','] = 1;
  2559.     notend_table['{'] = 1;
  2560.     notend_table['}'] = 1;
  2561.     alt_notend_table['a'] = 1;
  2562.     alt_notend_table['A'] = 1;
  2563.     alt_notend_table['d'] = 1;
  2564.     alt_notend_table['D'] = 1;
  2565.     alt_notend_table['#'] = 1;
  2566.     alt_notend_table['f'] = 1;
  2567.     alt_notend_table['F'] = 1;
  2568. #ifdef REGISTER_PREFIX
  2569.     alt_notend_table[REGISTER_PREFIX] = 1;
  2570. #endif
  2571. }
  2572.  
  2573. #if 0
  2574. #define notend(s) ((*s == ',' || *s == '}' || *s == '{' \
  2575.                    || (*s == ':' && index("aAdD#", s[1]))) \
  2576.                ? 0 : 1)
  2577. #endif
  2578.  
  2579. /* This funciton is called once, before the assembler exits.  It is
  2580.    supposed to do any final cleanup for this part of the assembler.
  2581.  */
  2582. void
  2583. md_end()
  2584. {
  2585. }
  2586.  
  2587. /* Equal to MAX_PRECISION in atof-ieee.c */
  2588. #define MAX_LITTLENUMS 6
  2589.  
  2590. /* Turn a string in input_line_pointer into a floating point constant of type
  2591.    type, and store the appropriate bytes in *litP.  The number of LITTLENUMS
  2592.    emitted is stored in *sizeP .  An error message is returned, or NULL on OK.
  2593.  */
  2594. char *
  2595. md_atof(type,litP,sizeP)
  2596. char type;
  2597. char *litP;
  2598. int *sizeP;
  2599. {
  2600.     int    prec;
  2601.     LITTLENUM_TYPE words[MAX_LITTLENUMS];
  2602.     LITTLENUM_TYPE *wordP;
  2603.     char    *t;
  2604.     char    *atof_ieee();
  2605.  
  2606.     switch(type) {
  2607.     case 'f':
  2608.     case 'F':
  2609.     case 's':
  2610.     case 'S':
  2611.         prec = 2;
  2612.         break;
  2613.  
  2614.     case 'd':
  2615.     case 'D':
  2616.     case 'r':
  2617.     case 'R':
  2618.         prec = 4;
  2619.         break;
  2620.  
  2621.     case 'x':
  2622.     case 'X':
  2623.         prec = 6;
  2624.         break;
  2625.  
  2626.     case 'p':
  2627.     case 'P':
  2628.         prec = 6;
  2629.         break;
  2630.  
  2631.     default:
  2632.         *sizeP=0;
  2633.         return "Bad call to MD_ATOF()";
  2634.     }
  2635.     t=atof_ieee(input_line_pointer,type,words);
  2636.     if(t)
  2637.         input_line_pointer=t;
  2638.  
  2639.     *sizeP=prec * sizeof(LITTLENUM_TYPE);
  2640.     for(wordP=words;prec--;) {
  2641.         md_number_to_chars(litP,(long)(*wordP++),sizeof(LITTLENUM_TYPE));
  2642.         litP+=sizeof(LITTLENUM_TYPE);
  2643.     }
  2644.     return "";    /* Someone should teach Dean about null pointers */
  2645. }
  2646.  
  2647. /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
  2648.    for use in the a.out file, and stores them in the array pointed to by buf.
  2649.    This knows about the endian-ness of the target machine and does
  2650.    THE RIGHT THING, whatever it is.  Possible values for n are 1 (byte)
  2651.    2 (short) and 4 (long)  Floating numbers are put out as a series of
  2652.    LITTLENUMS (shorts, here at least)
  2653.  */
  2654. void
  2655. md_number_to_chars(buf,val,n)
  2656. char    *buf;
  2657. long    val;
  2658. int n;
  2659. {
  2660.     switch(n) {
  2661.     case 1:
  2662.         *buf++=val;
  2663.         break;
  2664.     case 2:
  2665.         *buf++=(val>>8);
  2666.         *buf++=val;
  2667.         break;
  2668.     case 4:
  2669.         *buf++=(val>>24);
  2670.         *buf++=(val>>16);
  2671.         *buf++=(val>>8);
  2672.         *buf++=val;
  2673.         break;
  2674.     default:
  2675.         abort();
  2676.     }
  2677. }
  2678.  
  2679. void
  2680. md_number_to_imm(buf,val,n)
  2681. char *buf;
  2682. long val;
  2683. int n;
  2684. {
  2685.     switch(n) {
  2686.     case 1:
  2687.         *buf++=val;
  2688.         break;
  2689.     case 2:
  2690.         *buf++=(val>>8);
  2691.         *buf++=val;
  2692.         break;
  2693.     case 4:
  2694.         *buf++=(val>>24);
  2695.         *buf++=(val>>16);
  2696.         *buf++=(val>>8);
  2697.         *buf++=val;
  2698.         break;
  2699.     default:
  2700.         abort();
  2701.     }
  2702. }
  2703.  
  2704. void
  2705. md_number_to_disp(buf,val,n)
  2706. char    *buf;
  2707. long    val;
  2708. int n;
  2709. {
  2710.     abort();
  2711. }
  2712.  
  2713. void
  2714. md_number_to_field(buf,val,fix)
  2715. char *buf;
  2716. long val;
  2717. void *fix;
  2718. {
  2719.     abort();
  2720. }
  2721.  
  2722.  
  2723. /* *fragP has been relaxed to its final size, and now needs to have
  2724.    the bytes inside it modified to conform to the new size  There is UGLY
  2725.    MAGIC here. ..
  2726.  */
  2727. void
  2728. md_convert_frag(fragP)
  2729. register fragS *fragP;
  2730. {
  2731.   long disp;
  2732.   long ext;
  2733.  
  2734.   /* Address in gas core of the place to store the displacement.  */
  2735.   register char *buffer_address = fragP -> fr_fix + fragP -> fr_literal;
  2736.   /* Address in object code of the displacement.  */
  2737.   register int object_address = fragP -> fr_fix + fragP -> fr_address;
  2738.  
  2739.   know(fragP->fr_symbol);
  2740.  
  2741.   /* The displacement of the address, from current location.  */
  2742.   disp = (fragP->fr_symbol->sy_value + fragP->fr_offset) - object_address;
  2743.  
  2744.   switch(fragP->fr_subtype) {
  2745.   case TAB(BCC68000,BYTE):
  2746.   case TAB(BRANCH,BYTE):
  2747.     know(issbyte(disp));
  2748.     if(disp==0)
  2749.       as_bad("short branch with zero offset: use :w");
  2750.     fragP->fr_opcode[1]=disp;
  2751.     ext=0;
  2752.     break;
  2753.   case TAB(DBCC,SHORT):
  2754.     know(issword(disp));
  2755.     ext=2;
  2756.     break;
  2757.   case TAB(BCC68000,SHORT):
  2758.   case TAB(BRANCH,SHORT):
  2759.     know(issword(disp));
  2760.     fragP->fr_opcode[1]=0x00;
  2761.     ext=2;
  2762.     break;
  2763.   case TAB(BRANCH,LONG):
  2764.     if(flagseen['m']) {
  2765.       if(fragP->fr_opcode[0]==0x61) {
  2766.     fragP->fr_opcode[0]= 0x4E;
  2767.     fragP->fr_opcode[1]= 0xB9;    /* JBSR with ABSL LONG offset */
  2768.     subseg_change(SEG_TEXT, 0);
  2769.     fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2770.     fragP->fr_fix+=4;
  2771.     ext=0;
  2772.       } else if(fragP->fr_opcode[0]==0x60) {
  2773.         fragP->fr_opcode[0]= 0x4E;
  2774.         fragP->fr_opcode[1]= 0xF9;      /* JMP  with ABSL LONG offset */
  2775.         subseg_change(SEG_TEXT, 0);
  2776.         fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset,0);
  2777.         fragP->fr_fix+=4;
  2778.         ext=0;
  2779.       }else {
  2780.         as_bad("Long branch offset not supported.");
  2781.       }
  2782.     } else {
  2783.       fragP->fr_opcode[1]=0xff;
  2784.       ext=4;
  2785.     }
  2786.     break;
  2787.   case TAB(BCC68000,LONG):
  2788.     /* only Bcc 68000 instructions can come here */
  2789.         /* change bcc into b!cc/jmp absl long */
  2790.     fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
  2791.         fragP->fr_opcode[1] = 0x6;   /* branch offset = 6 */
  2792.  
  2793.     /* JF: these used to be fr_opcode[2,3], but they may be in a
  2794.        different frag, in which case refering to them is a no-no.
  2795.        Only fr_opcode[0,1] are guaranteed to work. */
  2796.         *buffer_address++ = 0x4e;  /* put in jmp long (0x4ef9) */ 
  2797.         *buffer_address++ = 0xf9;  
  2798.         fragP->fr_fix += 2;         /* account for jmp instruction */
  2799.         subseg_change(SEG_TEXT,0);
  2800.         fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, 
  2801.                      fragP->fr_offset,0);
  2802.         fragP->fr_fix += 4;
  2803.         ext=0;
  2804.     break;
  2805.   case TAB(DBCC,LONG):
  2806.         /* only DBcc 68000 instructions can come here */
  2807.         /* change dbcc into dbcc/jmp absl long */
  2808.     /* JF: these used to be fr_opcode[2-7], but that's wrong */
  2809.         *buffer_address++ = 0x00;  /* branch offset = 4 */
  2810.         *buffer_address++ = 0x04;  
  2811.         *buffer_address++ = 0x60;  /* put in bra pc+6 */ 
  2812.         *buffer_address++ = 0x06;  
  2813.         *buffer_address++ = 0x4e;  /* put in jmp long (0x4ef9) */ 
  2814.         *buffer_address++ = 0xf9;  
  2815.  
  2816.         fragP->fr_fix += 6;         /* account for bra/jmp instructions */
  2817.         subseg_change(SEG_TEXT,0);
  2818.         fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, 
  2819.                      fragP->fr_offset,0);
  2820.         fragP->fr_fix += 4;
  2821.         ext=0;
  2822.     break;
  2823.   case TAB(FBRANCH,SHORT):
  2824.     know((fragP->fr_opcode[1]&0x40)==0);
  2825.     ext=2;
  2826.     break;
  2827.   case TAB(FBRANCH,LONG):
  2828.     fragP->fr_opcode[1]|=0x40;    /* Turn on LONG bit */
  2829.     ext=4;
  2830.     break;
  2831.   case TAB(PCREL,SHORT):
  2832.     ext=2;
  2833.     break;
  2834.   case TAB(PCREL,LONG):
  2835.     /* The thing to do here is force it to ABSOLUTE LONG, since
  2836.        PCREL is really trying to shorten an ABSOLUTE address anyway */
  2837.     /* JF FOO This code has not been tested */
  2838.     subseg_change(SEG_TEXT,0);
  2839.     fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2840.     if((fragP->fr_opcode[1] & 0x3F) != 0x3A)
  2841.       as_bad("Internal error (long PC-relative operand) for insn 0x%04lx at 0x%lx",
  2842.             fragP->fr_opcode[0],fragP->fr_address);
  2843.     fragP->fr_opcode[1]&= ~0x3F;
  2844.     fragP->fr_opcode[1]|=0x39;    /* Mode 7.1 */
  2845.     fragP->fr_fix+=4;
  2846.     /* md_number_to_chars(buffer_address,
  2847.                (long)(fragP->fr_symbol->sy_value + fragP->fr_offset),
  2848.                4); */
  2849.     ext=0;
  2850.     break;
  2851.   case TAB(PCLEA,SHORT):
  2852.     subseg_change(SEG_TEXT,0);
  2853.     fix_new(fragP,(int)(fragP->fr_fix),2,fragP->fr_symbol,(symbolS *)0,fragP->fr_offset,1);
  2854.     fragP->fr_opcode[1] &= ~0x3F;
  2855.     fragP->fr_opcode[1] |= 0x3A;
  2856.     ext=2;
  2857.     break;
  2858.   case TAB(PCLEA,LONG):
  2859.     subseg_change(SEG_TEXT,0);
  2860.     fix_new(fragP,(int)(fragP->fr_fix)+2,4,fragP->fr_symbol,(symbolS *)0,fragP->fr_offset+2,1);
  2861.     *buffer_address++ = 0x01;
  2862.     *buffer_address++ = 0x70;
  2863.     fragP->fr_fix+=2;
  2864.     /* buffer_address+=2; */
  2865.     ext=4;
  2866.     break;
  2867.  
  2868.   }
  2869.   if(ext) {
  2870.     md_number_to_chars(buffer_address,(long)disp,(int)ext);
  2871.     fragP->fr_fix+=ext;
  2872.   }
  2873. }
  2874.  
  2875. /* Force truly undefined symbols to their maximum size, and generally set up
  2876.    the frag list to be relaxed
  2877.  */
  2878. int
  2879. md_estimate_size_before_relax(fragP,segtype)
  2880. register fragS *fragP;
  2881. int segtype;
  2882. {
  2883.     int    old_fix;
  2884.     register char *buffer_address = fragP -> fr_fix + fragP -> fr_literal;
  2885.  
  2886.     old_fix=fragP->fr_fix;
  2887.  
  2888.     /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
  2889.     switch(fragP->fr_subtype) {
  2890.     case TAB(BRANCH,SZ_UNDEF):
  2891.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  2892.             fragP->fr_subtype=TAB(TABTYPE(fragP->fr_subtype),BYTE);
  2893.             break;
  2894.         } else if(flagseen['m']) {
  2895.             if(fragP->fr_opcode[0]==0x61) {
  2896.                 if(flagseen['l']) {
  2897.                     fragP->fr_opcode[0]= 0x4E;
  2898.                     fragP->fr_opcode[1]= 0xB8;    /* JBSR with ABSL WORD offset */
  2899.                     subseg_change(SEG_TEXT, 0);
  2900.                     fix_new(fragP, fragP->fr_fix, 2, 
  2901.                         fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2902.                     fragP->fr_fix+=2;
  2903.                 } else {
  2904.                     fragP->fr_opcode[0]= 0x4E;
  2905.                     fragP->fr_opcode[1]= 0xB9;    /* JBSR with ABSL LONG offset */
  2906.                     subseg_change(SEG_TEXT, 0);
  2907.                     fix_new(fragP, fragP->fr_fix, 4, 
  2908.                         fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2909.                     fragP->fr_fix+=4;
  2910.                 }
  2911.                 frag_wane(fragP);
  2912.             } else if(fragP->fr_opcode[0]==0x60) {
  2913.                 if(flagseen['l']) {
  2914.                     fragP->fr_opcode[0]= 0x4E;
  2915.                     fragP->fr_opcode[1]= 0xF8;    /* JMP    with ABSL WORD offset */
  2916.                     subseg_change(SEG_TEXT, 0);
  2917.                     fix_new(fragP, fragP->fr_fix, 2, 
  2918.                         fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2919.                     fragP->fr_fix+=2;
  2920.                 } else {
  2921.                     fragP->fr_opcode[0]= 0x4E;
  2922.                     fragP->fr_opcode[1]= 0xF9;    /* JMP    with ABSL LONG offset */
  2923.                     subseg_change(SEG_TEXT, 0);
  2924.                     fix_new(fragP, fragP->fr_fix, 4, 
  2925.                         fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2926.                     fragP->fr_fix+=4;
  2927.                 }
  2928.                 frag_wane(fragP);
  2929.             } else {
  2930.                 as_warn("Long branch offset to extern symbol not supported.");
  2931.             }
  2932.         } else if(flagseen['l']) {    /* Symbol is still undefined.  Make it simple */
  2933.             fix_new(fragP,(int)(fragP->fr_fix),2,fragP->fr_symbol,
  2934.  (symbolS *)0,fragP->fr_offset + 2,1);
  2935.             fragP->fr_fix+=2;
  2936.             fragP->fr_opcode[1]=0x00;
  2937.             frag_wane(fragP);
  2938.         } else {
  2939.             fix_new(fragP,(int)(fragP->fr_fix),4,fragP->fr_symbol,
  2940.  (symbolS *)0,fragP->fr_offset + 4,1);
  2941.             fragP->fr_fix+=4;
  2942.             fragP->fr_opcode[1]=0xff;
  2943.             frag_wane(fragP);
  2944.             break;
  2945.         }
  2946.         break;
  2947.  
  2948.     case TAB(FBRANCH,SZ_UNDEF):
  2949.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype || flagseen['l']) {
  2950.             fragP->fr_subtype=TAB(FBRANCH,SHORT);
  2951.             fragP->fr_var+=2;
  2952.         } else {
  2953.             fragP->fr_subtype=TAB(FBRANCH,LONG);
  2954.             fragP->fr_var+=4;
  2955.         }
  2956.         break;
  2957.  
  2958.     case TAB(PCREL,SZ_UNDEF):
  2959.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype || flagseen['l']) {
  2960.             fragP->fr_subtype=TAB(PCREL,SHORT);
  2961.             fragP->fr_var+=2;
  2962.         } else {
  2963.             fragP->fr_subtype=TAB(PCREL,LONG);
  2964.             fragP->fr_var+=4;
  2965.         }
  2966.         break;
  2967.  
  2968.     case TAB(BCC68000,SZ_UNDEF):
  2969.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  2970.             fragP->fr_subtype=TAB(BCC68000,BYTE);
  2971.             break;
  2972.         }
  2973.         /* only Bcc 68000 instructions can come here */
  2974.         /* change bcc into b!cc/jmp absl long */
  2975.         fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
  2976.         if(flagseen['l']) {
  2977.             fragP->fr_opcode[1] = 0x04;   /* branch offset = 6 */
  2978.             /* JF: these were fr_opcode[2,3] */
  2979.             buffer_address[0] = 0x4e;  /* put in jmp long (0x4ef9) */ 
  2980.             buffer_address[1] = 0xf8;
  2981.             fragP->fr_fix += 2;         /* account for jmp instruction */
  2982.             subseg_change(SEG_TEXT,0);
  2983.             fix_new(fragP, fragP->fr_fix, 2, fragP->fr_symbol, 0, 
  2984.                              fragP->fr_offset,0);
  2985.             fragP->fr_fix += 2;
  2986.         } else {
  2987.             fragP->fr_opcode[1] = 0x06;   /* branch offset = 6 */
  2988.             /* JF: these were fr_opcode[2,3] */
  2989.             buffer_address[2] = 0x4e;  /* put in jmp long (0x4ef9) */ 
  2990.             buffer_address[3] = 0xf9;
  2991.             fragP->fr_fix += 2;         /* account for jmp instruction */
  2992.             subseg_change(SEG_TEXT,0);
  2993.             fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, 
  2994.                              fragP->fr_offset,0);
  2995.             fragP->fr_fix += 4;
  2996.         }
  2997.         frag_wane(fragP);
  2998.         break;
  2999.  
  3000.     case TAB(DBCC,SZ_UNDEF):
  3001.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  3002.             fragP->fr_subtype=TAB(DBCC,SHORT);
  3003.             fragP->fr_var+=2;
  3004.             break;
  3005.         }
  3006.         /* only DBcc 68000 instructions can come here */
  3007.         /* change dbcc into dbcc/jmp absl long */
  3008.         /* JF: these used to be fr_opcode[2-4], which is wrong. */
  3009.         buffer_address[0] = 0x00;  /* branch offset = 4 */
  3010.         buffer_address[1] = 0x04;  
  3011.         buffer_address[2] = 0x60;  /* put in bra pc + ... */ 
  3012.         if(flagseen['l']) {
  3013.             /* JF: these were fr_opcode[5-7] */
  3014.             buffer_address[3] = 0x04; /* plus 4 */
  3015.             buffer_address[4] = 0x4e;/* Put in Jump Word */
  3016.             buffer_address[5] = 0xf8;
  3017.             fragP->fr_fix += 6;      /* account for bra/jmp instruction */
  3018.             subseg_change(SEG_TEXT,0);
  3019.             fix_new(fragP, fragP->fr_fix, 2, fragP->fr_symbol, 0, 
  3020.                              fragP->fr_offset,0);
  3021.             fragP->fr_fix+=2;
  3022.         } else {
  3023.             /* JF: these were fr_opcode[5-7] */
  3024.             buffer_address[3] = 0x06;  /* Plus 6 */
  3025.             buffer_address[4] = 0x4e;  /* put in jmp long (0x4ef9) */ 
  3026.             buffer_address[5] = 0xf9;  
  3027.             fragP->fr_fix += 6;      /* account for bra/jmp instruction */
  3028.             subseg_change(SEG_TEXT,0);
  3029.             fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, 
  3030.                              fragP->fr_offset,0);
  3031.             fragP->fr_fix += 4;
  3032.         }
  3033.         frag_wane(fragP);
  3034.         break;
  3035.  
  3036.     case TAB(PCLEA,SZ_UNDEF):
  3037.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype || flagseen['l']) {
  3038.             fragP->fr_subtype=TAB(PCLEA,SHORT);
  3039.             fragP->fr_var+=2;
  3040.         } else {
  3041.             fragP->fr_subtype=TAB(PCLEA,LONG);
  3042.             fragP->fr_var+=6;
  3043.         }
  3044.         break;
  3045.  
  3046.     default:
  3047.         break;
  3048.     }
  3049.  
  3050.     /* now that SZ_UNDEF are taken care of, check others */
  3051.     switch(fragP->fr_subtype) {
  3052.     case TAB(BCC68000,BYTE):
  3053.     case TAB(BRANCH,BYTE):
  3054.             /* We can't do a short jump to the next instruction,
  3055.                so we force word mode.  */
  3056.         if(fragP->fr_symbol && fragP->fr_symbol->sy_value==0 &&
  3057.  fragP->fr_symbol->sy_frag==fragP->fr_next) {
  3058.             fragP->fr_subtype=TAB(TABTYPE(fragP->fr_subtype),SHORT);
  3059.             fragP->fr_var+=2;
  3060.         }
  3061.         break;
  3062.     default:
  3063.         break;
  3064.     }
  3065.     return fragP->fr_var + fragP->fr_fix - old_fix;
  3066. }
  3067.  
  3068. /* the bit-field entries in the relocation_info struct plays hell 
  3069.    with the byte-order problems of cross-assembly.  So as a hack,
  3070.    I added this mach. dependent ri twiddler.  Ugly, but it gets
  3071.    you there. -KWK */
  3072. /* on m68k: first 4 bytes are normal unsigned long, next three bytes
  3073. are symbolnum, most sig. byte first.  Last byte is broken up with
  3074. bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
  3075. nibble as nuthin. (on Sun 3 at least) */
  3076. void
  3077. md_ri_to_chars(ri_p, ri)
  3078.      struct relocation_info *ri_p, ri;
  3079. {
  3080.   unsigned char the_bytes[8];
  3081.  
  3082.   /* this is easy */
  3083.   md_number_to_chars(the_bytes, ri.r_address, sizeof(ri.r_address));
  3084.   /* now the fun stuff */
  3085.   the_bytes[4] = (ri.r_symbolnum >> 16) & 0x0ff;
  3086.   the_bytes[5] = (ri.r_symbolnum >> 8) & 0x0ff;
  3087.   the_bytes[6] = ri.r_symbolnum & 0x0ff;
  3088.   the_bytes[7] = (((ri.r_pcrel << 7)  & 0x80) | ((ri.r_length << 5) & 0x60) | 
  3089.     ((ri.r_extern << 4)  & 0x10)); 
  3090.   /* now put it back where you found it */
  3091.   bcopy (the_bytes, (char *)ri_p, sizeof(struct relocation_info));
  3092. }
  3093.  
  3094. #ifndef WORKING_DOT_WORD
  3095. const int md_short_jump_size = 4;
  3096. const int md_long_jump_size = 6;
  3097.  
  3098. void
  3099. md_create_short_jump(ptr,from_addr,to_addr,frag,to_symbol)
  3100. char    *ptr;
  3101. long    from_addr,
  3102.     to_addr;
  3103. fragS    *frag;
  3104. symbolS    *to_symbol;
  3105. {
  3106.     long offset;
  3107.  
  3108.     offset = to_addr - (from_addr+2);
  3109.  
  3110.     md_number_to_chars(ptr  ,(long)0x6000,2);
  3111.     md_number_to_chars(ptr+2,(long)offset,2);
  3112. }
  3113.  
  3114. void
  3115. md_create_long_jump(ptr,from_addr,to_addr,frag,to_symbol)
  3116. char    *ptr;
  3117. long    from_addr,
  3118.     to_addr;
  3119. fragS    *frag;
  3120. symbolS    *to_symbol;
  3121. {
  3122.     long offset;
  3123.  
  3124.     if(flagseen['m']) {
  3125.         offset=to_addr-to_symbol->sy_value;
  3126.         md_number_to_chars(ptr  ,(long)0x4EF9,2);
  3127.         md_number_to_chars(ptr+2,(long)offset,4);
  3128.         fix_new(frag,(ptr+2)-frag->fr_literal,4,to_symbol,(symbolS *)0,(long int)0,0);
  3129.     } else {
  3130.         offset=to_addr - (from_addr+2);
  3131.         md_number_to_chars(ptr  ,(long)0x60ff,2);
  3132.         md_number_to_chars(ptr+2,(long)offset,4);
  3133.     }
  3134. }
  3135.  
  3136. #endif
  3137. /* Different values of OK tell what its OK to return.  Things that aren't OK are an error (what a shock, no?)
  3138.  
  3139.     0:  Everything is OK
  3140.     10:  Absolute 1:8    only
  3141.     20:  Absolute 0:7    only
  3142.     30:  absolute 0:15    only
  3143.     40:  Absolute 0:31    only
  3144.     50:  absolute 0:127    only
  3145.     55:  absolute -64:63    only
  3146.     60:  absolute -128:127    only
  3147.     70:  absolute 0:4095    only
  3148.     80:  No bignums
  3149.  
  3150. */
  3151. int
  3152. get_num(exp,ok)
  3153. struct m68k_exp *exp;
  3154. int ok;
  3155. {
  3156. #ifdef TEST2
  3157.     long    l = 0;
  3158.  
  3159.     if(!exp->e_beg)
  3160.         return 0;
  3161.     if(*exp->e_beg=='0') {
  3162.         if(exp->e_beg[1]=='x')
  3163.             sscanf(exp->e_beg+2,"%x",&l);
  3164.         else
  3165.             sscanf(exp->e_beg+1,"%O",&l);
  3166.         return l;
  3167.     }
  3168.     return atol(exp->e_beg);
  3169. #else
  3170.     char    *save_in;
  3171.     char    c_save;
  3172.  
  3173.     if(!exp) {
  3174.         /* Can't do anything */
  3175.         return 0;
  3176.     }
  3177.     if(!exp->e_beg || !exp->e_end) {
  3178.         seg(exp)=SEG_ABSOLUTE;
  3179.         adds(exp)=0;
  3180.         subs(exp)=0;
  3181.         offs(exp)= (ok==10) ? 1 : 0;
  3182.         as_warn("Null expression defaults to %ld",offs(exp));
  3183.         return 0;
  3184.     }
  3185.  
  3186.     exp->e_siz=0;
  3187.     if(/* ok!=80 && */exp->e_end[-1]==':' && (exp->e_end-exp->e_beg)>=2) {
  3188.         switch(exp->e_end[0]) {
  3189.         case 's':
  3190.         case 'S':
  3191.         case 'b':
  3192.         case 'B':
  3193.             exp->e_siz=1;
  3194.             break;
  3195.         case 'w':
  3196.         case 'W':
  3197.             exp->e_siz=2;
  3198.             break;
  3199.         case 'l':
  3200.         case 'L':
  3201.             exp->e_siz=3;
  3202.             break;
  3203.         default:
  3204.             as_bad("Unknown size for expression \"%c\"",exp->e_end[0]);
  3205.         }
  3206.         exp->e_end-=2;
  3207.     }
  3208.     c_save=exp->e_end[1];
  3209.     exp->e_end[1]='\0';
  3210.     save_in=input_line_pointer;
  3211.     input_line_pointer=exp->e_beg;
  3212.     switch(expression(&(exp->e_exp))) {
  3213.     case SEG_PASS1:
  3214.         seg(exp)=SEG_ABSOLUTE;
  3215.         adds(exp)=0;
  3216.         subs(exp)=0;
  3217.         offs(exp)= (ok==10) ? 1 : 0;
  3218.         as_warn("Unknown expression: '%s' defaulting to %d",exp->e_beg,offs(exp));
  3219.         break;
  3220.  
  3221.     case SEG_NONE:
  3222.         /* Do the same thing the VAX asm does */
  3223.         seg(exp)=SEG_ABSOLUTE;
  3224.         adds(exp)=0;
  3225.         subs(exp)=0;
  3226.         offs(exp)=0;
  3227.         if(ok==10) {
  3228.             as_warn("expression out of range: defaulting to 1");
  3229.             offs(exp)=1;
  3230.         }
  3231.         break;
  3232.     case SEG_ABSOLUTE:
  3233.         switch(ok) {
  3234.         case 10:
  3235.             if(offs(exp)<1 || offs(exp)>8) {
  3236.                 as_warn("expression out of range: defaulting to 1");
  3237.                 offs(exp)=1;
  3238.             }
  3239.             break;
  3240.         case 20:
  3241.             if(offs(exp)<0 || offs(exp)>7)
  3242.                 goto outrange;
  3243.             break;
  3244.         case 30:
  3245.             if(offs(exp)<0 || offs(exp)>15)
  3246.                 goto outrange;
  3247.             break;
  3248.         case 40:
  3249.             if(offs(exp)<0 || offs(exp)>32)
  3250.                 goto outrange;
  3251.             break;
  3252.         case 50:
  3253.             if(offs(exp)<0 || offs(exp)>127)
  3254.                 goto outrange;
  3255.             break;
  3256.         case 55:
  3257.             if(offs(exp)<-64 || offs(exp)>63)
  3258.                 goto outrange;
  3259.             break;
  3260.         case 60:
  3261.             if(offs(exp)<-128 || offs(exp)>127)
  3262.                 goto outrange;
  3263.             break;
  3264.         case 70:
  3265.             if(offs(exp)<0 || offs(exp)>4095) {
  3266.             outrange:
  3267.                 as_warn("expression out of range: defaulting to 0");
  3268.                 offs(exp)=0;
  3269.             }
  3270.             break;
  3271.         default:
  3272.             break;
  3273.         }
  3274.         break;
  3275.     case SEG_TEXT:
  3276.     case SEG_DATA:
  3277.     case SEG_BSS:
  3278.     case SEG_UNKNOWN:
  3279.     case SEG_DIFFERENCE:
  3280.         if(ok>=10 && ok<=70) {
  3281.             seg(exp)=SEG_ABSOLUTE;
  3282.             adds(exp)=0;
  3283.             subs(exp)=0;
  3284.             offs(exp)= (ok==10) ? 1 : 0;
  3285.             as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp->e_beg,offs(exp));
  3286.         }
  3287.         break;
  3288.     case SEG_BIG:
  3289.         if(ok==80 && offs(exp)<0) {    /* HACK! Turn it into a long */
  3290.             LITTLENUM_TYPE words[6];
  3291.  
  3292.             gen_to_words(words,2,8L);/* These numbers are magic! */
  3293.             seg(exp)=SEG_ABSOLUTE;
  3294.             adds(exp)=0;
  3295.             subs(exp)=0;
  3296.             offs(exp)=words[1]|(words[0]<<16);
  3297.         } else if(ok!=0) {
  3298.             seg(exp)=SEG_ABSOLUTE;
  3299.             adds(exp)=0;
  3300.             subs(exp)=0;
  3301.             offs(exp)= (ok==10) ? 1 : 0;
  3302.             as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp->e_beg,offs(exp));
  3303.         }
  3304.         break;
  3305.     default:
  3306.         abort();
  3307.     }
  3308.     if(input_line_pointer!=exp->e_end+1)
  3309.         as_bad("Ignoring junk after expression");
  3310.     exp->e_end[1]=c_save;
  3311.     input_line_pointer=save_in;
  3312.     if(exp->e_siz) {
  3313.         switch(exp->e_siz) {
  3314.         case 1:
  3315.             if(!isbyte(offs(exp)))
  3316.                 as_warn("expression doesn't fit in BYTE");
  3317.             break;
  3318.         case 2:
  3319.             if(!isword(offs(exp)))
  3320.                 as_warn("expression doesn't fit in WORD");
  3321.             break;
  3322.         }
  3323.     }
  3324.     return offs(exp);
  3325. #endif
  3326. }
  3327.  
  3328. /* These are the back-ends for the various machine dependent pseudo-ops.  */
  3329. void demand_empty_rest_of_line();    /* Hate those extra verbose names */
  3330.  
  3331. void
  3332. s_data1()
  3333. {
  3334.     subseg_new(SEG_DATA,1);
  3335.     demand_empty_rest_of_line();
  3336. }
  3337.  
  3338. void
  3339. s_data2()
  3340. {
  3341.     subseg_new(SEG_DATA,2);
  3342.     demand_empty_rest_of_line();
  3343. }
  3344.  
  3345. void
  3346. s_even()
  3347. {
  3348.     register int temp;
  3349.     register long int temp_fill;
  3350.  
  3351.     temp = 1;        /* JF should be 2? */
  3352.     temp_fill = get_absolute_expression ();
  3353.     if ( ! need_pass_2 ) /* Never make frag if expect extra pass. */
  3354.         frag_align (temp, (int)temp_fill);
  3355.     demand_empty_rest_of_line();
  3356. }
  3357.  
  3358. void
  3359. s_proc()
  3360. {
  3361.     demand_empty_rest_of_line();
  3362. }
  3363.  
  3364. /* s_space is defined in read.c .skip is simply an alias to it. */
  3365.  
  3366. int
  3367. md_parse_option(argP,cntP,vecP)
  3368. char **argP;
  3369. int *cntP;
  3370. char ***vecP;
  3371. {
  3372.     switch(**argP) {
  3373.     case 'l':    /* -l means keep external to 2 bit offset
  3374.                rather than 16 bit one */
  3375.         break;
  3376.  
  3377.     case 'm':
  3378.         /* Gas almost ignores this option! */
  3379.         (*argP)++;
  3380.         if(**argP=='c')
  3381.             (*argP)++;
  3382.         if(!strcmp(*argP,"68000"))
  3383.             flagseen['m']=2;
  3384.         else if(!strcmp(*argP,"68010")) {
  3385. #ifdef M_SUN
  3386.             omagic= 1<<16|OMAGIC;
  3387. #endif
  3388.             flagseen['m']=1;
  3389.         } else if(!strcmp(*argP,"68020"))
  3390.             flagseen['m']=0;
  3391.         else
  3392.             as_warn("Unknown -m option ignored");
  3393.         while(**argP)
  3394.             (*argP)++;
  3395.         break;
  3396.  
  3397.     default:
  3398.         return 0;
  3399.     }
  3400.     return 1;
  3401. }
  3402.  
  3403.  
  3404. #ifdef TEST2
  3405.  
  3406. /* TEST2:  Test md_assemble() */
  3407. /* Warning, this routine probably doesn't work anymore */
  3408.  
  3409. main()
  3410. {
  3411.     struct m68_it the_ins;
  3412.     char buf[120];
  3413.     char *cp;
  3414.     int    n;
  3415.  
  3416.     m68_ip_begin();
  3417.     for(;;) {
  3418.         if(!gets(buf) || !*buf)
  3419.             break;
  3420.         if(buf[0]=='|' || buf[1]=='.')
  3421.             continue;
  3422.         for(cp=buf;*cp;cp++)
  3423.             if(*cp=='\t')
  3424.                 *cp=' ';
  3425.         if(is_label(buf))
  3426.             continue;
  3427.         bzero(&the_ins,sizeof(the_ins));
  3428.         m68_ip(&the_ins,buf);
  3429.         if(the_ins.error) {
  3430.             printf("Error %s in %s\n",the_ins.error,buf);
  3431.         } else {
  3432.             printf("Opcode(%d.%s): ",the_ins.numo,the_ins.args);
  3433.             for(n=0;n<the_ins.numo;n++)
  3434.                 printf(" 0x%x",the_ins.opcode[n]&0xffff);
  3435.             printf("    ");
  3436.             print_the_insn(&the_ins.opcode[0],stdout);
  3437.             (void)putchar('\n');
  3438.         }
  3439.         for(n=0;n<strlen(the_ins.args)/2;n++) {
  3440.             if(the_ins.operands[n].error) {
  3441.                 printf("op%d Error %s in %s\n",n,the_ins.operands[n].error,buf);
  3442.                 continue;
  3443.             }
  3444.             printf("mode %d, reg %d, ",the_ins.operands[n].mode,the_ins.operands[n].reg);
  3445.             if(the_ins.operands[n].b_const)
  3446.                 printf("Constant: '%.*s', ",1+the_ins.operands[n].e_const-the_ins.operands[n].b_const,the_ins.operands[n].b_const);
  3447.             printf("ireg %d, isiz %d, imul %d, ",the_ins.operands[n].ireg,the_ins.operands[n].isiz,the_ins.operands[n].imul);
  3448.             if(the_ins.operands[n].b_iadd)
  3449.                 printf("Iadd: '%.*s',",1+the_ins.operands[n].e_iadd-the_ins.operands[n].b_iadd,the_ins.operands[n].b_iadd);
  3450.             (void)putchar('\n');
  3451.         }
  3452.     }
  3453.     m68_ip_end();
  3454.     return 0;
  3455. }
  3456.  
  3457. is_label(str)
  3458. char *str;
  3459. {
  3460.     while(*str==' ')
  3461.         str++;
  3462.     while(*str && *str!=' ')
  3463.         str++;
  3464.     if(str[-1]==':' || str[1]=='=')
  3465.         return 1;
  3466.     return 0;
  3467. }
  3468.  
  3469. #endif
  3470.  
  3471. /* Possible states for relaxation:
  3472.  
  3473. 0 0    branch offset    byte    (bra, etc)
  3474. 0 1            word
  3475. 0 2            long
  3476.  
  3477. 1 0    indexed offsets    byte    a0@(32,d4:w:1) etc
  3478. 1 1            word
  3479. 1 2            long
  3480.  
  3481. 2 0    two-offset index word-word a0@(32,d4)@(45) etc
  3482. 2 1            word-long
  3483. 2 2            long-word
  3484. 2 3            long-long
  3485.  
  3486. */
  3487.  
  3488.  
  3489.  
  3490. #ifdef DONTDEF
  3491. abort()
  3492. {
  3493.     printf("ABORT!\n");
  3494.     exit(12);
  3495. }
  3496.  
  3497. char *index(s,c)
  3498. char *s;
  3499. {
  3500.     while(*s!=c) {
  3501.         if(!*s) return 0;
  3502.         s++;
  3503.     }
  3504.     return s;
  3505. }
  3506.  
  3507. bzero(s,n)
  3508. char *s;
  3509. {
  3510.     while(n--)
  3511.         *s++=0;
  3512. }
  3513.  
  3514. print_frags()
  3515. {
  3516.     fragS *fragP;
  3517.     extern fragS *text_frag_root;
  3518.  
  3519.     for(fragP=text_frag_root;fragP;fragP=fragP->fr_next) {
  3520.         printf("addr %lu  next 0x%x  fix %ld  var %ld  symbol 0x%x  offset %ld\n",
  3521.  fragP->fr_address,fragP->fr_next,fragP->fr_fix,fragP->fr_var,fragP->fr_symbol,fragP->fr_offset);
  3522.         printf("opcode 0x%x  type %d  subtype %d\n\n",fragP->fr_opcode,fragP->fr_type,fragP->fr_subtype);
  3523.     }
  3524.     fflush(stdout);
  3525.     return 0;
  3526. }
  3527. #endif
  3528.  
  3529. #ifdef DONTDEF
  3530. /*VARARGS1*/
  3531. panic(format,args)
  3532. char *format;
  3533. {
  3534.     fputs("Internal error:",stderr);
  3535.     _doprnt(format,&args,stderr);
  3536.     (void)putc('\n',stderr);
  3537.     as_where();
  3538.     abort();
  3539. }
  3540. #endif
  3541.